private bool sendEmail() { List <string> MyEmailList = new List <string>(); MyEmailList.Add(tbEmailAddress.Text); EmailAttachment MyEmailAttachment = new EmailAttachment(); using (FileStream fileStream = File.OpenRead(Server.MapPath("/AttachmentExample.txt"))) { MemoryStream memStream = new MemoryStream(); memStream.SetLength(fileStream.Length); fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length); MyEmailAttachment.AttachmentMemoryStream = memStream; MyEmailAttachment.AttachmentFileInfo = new FileInfo(Server.MapPath("/AttachmentExample.txt")); } List <EmailAttachment> MyEmailAttachmentList = new List <EmailAttachment>(); MyEmailAttachmentList.Add(MyEmailAttachment); Email MyEmail = new Email(MyEmailList, MyEmailAttachmentList, "Test subject", "Test body", null, ConfigurationManager.AppSettings["EmailFrom"]); if (!MyEmail.SendEmail()) { ErrorMessage = MyEmail.ErrorMessage; return(false); } return(true); }
private bool sendEmail() { List<string> MyEmailList = new List<string>(); MyEmailList.Add(tbEmailAddress.Text); EmailAttachment MyEmailAttachment = new EmailAttachment(); using (FileStream fileStream = File.OpenRead(Server.MapPath("/AttachmentExample.txt"))) { MemoryStream memStream = new MemoryStream(); memStream.SetLength(fileStream.Length); fileStream.Read(memStream.GetBuffer(), 0, (int)fileStream.Length); MyEmailAttachment.AttachmentMemoryStream = memStream; MyEmailAttachment.AttachmentFileInfo = new FileInfo(Server.MapPath("/AttachmentExample.txt")); } List<EmailAttachment> MyEmailAttachmentList = new List<EmailAttachment>(); MyEmailAttachmentList.Add(MyEmailAttachment); Email MyEmail = new Email(MyEmailList, MyEmailAttachmentList, "Test subject", "Test body", null, ConfigurationManager.AppSettings["EmailFrom"]); if (!MyEmail.SendEmail()) { ErrorMessage = MyEmail.ErrorMessage; return false; } return true; }