I am dynamically storing each person report as pdf
and should send it to them an email Attacment
. How do I send it as an attachment to an email. Here is my code.
public void Esendmail(string EmailFrom, string EmailTo,
string EmailBody, string EmailSubject, string EmailCC)
{
MailMessage message = new MailMessage();
message.From = new MailAddress(EmailFrom);
message.CC.Add(EmailCC);
message.To.Add(new MailAddress(EmailTo));
message.IsBodyHtml = true;
message.Body = EmailBody;
message.Subject = EmailSubject;
SmtpClient client = new SmtpClient();
client.Send(message);
}
Use this sample code
MailMessage message = new MailMessage();
message.To = "[email protected]";
message.From = "[email protected]";
message.Subject = "mail with pdf";
message.Body = "your pdf attached";
message.Attachments.Add(new Attachment(@"c:\pdftoattach.pdf"));
SmtpMail.SmtpServer = "mail.domain.com";
SmtpMail.Send(message);
MailMessage message = new MailMessage();
FileStream fileStream = File.Create("PdfPath");
var memoryStream = new MemoryStream();
fileStream.Position = 0;
fileStream.CopyTo(memoryStream);
message.Attachments.Add(new Attachment(memoryStream,Path.GetFileName("PdfPath")));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With