public async Task CanSendEmailWithAttachments() { const string subject = "SendMail With Attachments Test"; const string body = "This email is testing the attachment functionality of SendGrid Sender."; using (var stream = File.OpenRead($"{Directory.GetCurrentDirectory()}/test-binary.xlsx")) { var attachment = new Attachment() { Data = stream, ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", Filename = "test-binary.xlsx" }; var email = Email .From(fromEmail, fromName) .To(toEmail, toName) .Subject(subject) .Body(body) .Attach(attachment); var response = await email.SendAsync(); Assert.IsTrue(response.Successful); } }
public async Task CanSendEmailWithAttachments() { var stream = new MemoryStream(); var sw = new StreamWriter(stream); sw.WriteLine("Hey this is some text in an attachment"); sw.Flush(); stream.Seek(0, SeekOrigin.Begin); var attachment = new Attachment { Data = stream, ContentType = "text/plain", Filename = "mailgunTest.txt" }; var email = Email .From(fromEmail) .To(toEmail) .Subject(subject) .Body(body) .Attach(attachment); var response = await email.SendAsync(); var files = Directory.EnumerateFiles(tempDirectory, "*.eml"); Assert.IsTrue(response.Successful); Assert.IsNotEmpty(files); }
public Attachment(FluentEmail.Core.Models.Attachment attachment) { this.swiftAttachment = attachment; }