Skip to content

Commit 5fc489b

Browse files
committed
feat: (SendGrid): Add content disposition on attachments . Contrib via @spewu lukencode#336
1 parent 67816e6 commit 5fc489b

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/Senders/FluentEmail.SendGrid/SendGridSender.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading;
66
using System.Threading.Tasks;
77
using FluentEmail.Core;
8-
using FluentEmail.Core.Interfaces;
98
using FluentEmail.Core.Models;
109
using SendGrid;
1110
using SendGrid.Helpers.Mail;
@@ -46,9 +45,7 @@ public async Task<SendResponse> SendAsync(IFluentEmail email, CancellationToken?
4645
mailMessage.PlainTextContent = email.Data.PlaintextAlternativeBody;
4746
}
4847

49-
var sendResponse = await SendViaSendGrid(mailMessage, token);
50-
51-
return sendResponse;
48+
return await SendViaSendGrid(mailMessage, token);
5249
}
5350

5451
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
175172
return sendResponse;
176173
}
177174

178-
private EmailAddress ConvertAddress(Address address) => new EmailAddress(address.EmailAddress, address.Name);
175+
private EmailAddress ConvertAddress(Address address) => new(address.EmailAddress, address.Name);
179176

180-
private async Task<SendGridAttachment> ConvertAttachment(Core.Models.Attachment attachment) => new SendGridAttachment
177+
private async Task<SendGridAttachment> ConvertAttachment(Core.Models.Attachment attachment) => new()
181178
{
182179
Content = await GetAttachmentBase64String(attachment.Data),
183180
Filename = attachment.Filename,
184-
Type = attachment.ContentType
181+
Type = attachment.ContentType,
182+
Disposition = attachment.IsInline
183+
? "inline"
184+
: "attachment",
185+
ContentId = attachment.ContentId
185186
};
186187

187188
private async Task<string> GetAttachmentBase64String(Stream stream)
188189
{
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());
194193
}
195194

196195
private bool IsHttpSuccess(int statusCode)
197196
{
198-
return statusCode >= 200 && statusCode < 300;
197+
return statusCode is >= 200 and < 300;
199198
}
200199
}
201200
}

0 commit comments

Comments
 (0)