|
5 | 5 | using System.Threading; |
6 | 6 | using System.Threading.Tasks; |
7 | 7 | using FluentEmail.Core; |
8 | | -using FluentEmail.Core.Interfaces; |
9 | 8 | using FluentEmail.Core.Models; |
10 | 9 | using SendGrid; |
11 | 10 | using SendGrid.Helpers.Mail; |
@@ -46,9 +45,7 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken? |
46 | 45 | mailMessage.PlainTextContent = email.Data.PlaintextAlternativeBody; |
47 | 46 | } |
48 | 47 |
|
49 | | - var sendResponse = await SendViaSendGrid(mailMessage, token); |
50 | | - |
51 | | - return sendResponse; |
| 48 | + return await SendViaSendGrid(mailMessage, token); |
52 | 49 | } |
53 | 50 |
|
54 | 51 | public async Task<SendResponse> SendWithTemplateAsync(IFluentEmail email, string templateId, object templateData, CancellationToken? token = null) |
@@ -175,27 +172,29 @@ private async Task<SendResponse> SendViaSendGrid(SendGridMessage mailMessage, Ca |
175 | 172 | return sendResponse; |
176 | 173 | } |
177 | 174 |
|
178 | | - private EmailAddress ConvertAddress(Address address) => new EmailAddress(address.EmailAddress, address.Name); |
| 175 | + private EmailAddress ConvertAddress(Address address) => new(address.EmailAddress, address.Name); |
179 | 176 |
|
180 | | - private async Task<SendGridAttachment> ConvertAttachment(Core.Models.Attachment attachment) => new SendGridAttachment |
| 177 | + private async Task<SendGridAttachment> ConvertAttachment(Core.Models.Attachment attachment) => new() |
181 | 178 | { |
182 | 179 | Content = await GetAttachmentBase64String(attachment.Data), |
183 | 180 | Filename = attachment.Filename, |
184 | | - Type = attachment.ContentType |
| 181 | + Type = attachment.ContentType, |
| 182 | + Disposition = attachment.IsInline |
| 183 | + ? "inline" |
| 184 | + : "attachment", |
| 185 | + ContentId = attachment.ContentId |
185 | 186 | }; |
186 | 187 |
|
187 | 188 | private async Task<string> GetAttachmentBase64String(Stream stream) |
188 | 189 | { |
189 | | - using (var ms = new MemoryStream()) |
190 | | - { |
191 | | - await stream.CopyToAsync(ms); |
192 | | - return Convert.ToBase64String(ms.ToArray()); |
193 | | - } |
| 190 | + using var ms = new MemoryStream(); |
| 191 | + await stream.CopyToAsync(ms); |
| 192 | + return Convert.ToBase64String(ms.ToArray()); |
194 | 193 | } |
195 | 194 |
|
196 | 195 | private bool IsHttpSuccess(int statusCode) |
197 | 196 | { |
198 | | - return statusCode >= 200 && statusCode < 300; |
| 197 | + return statusCode is >= 200 and < 300; |
199 | 198 | } |
200 | 199 | } |
201 | 200 | } |
0 commit comments