Send Email
with Attachment
with CC
with HTML body
using System.Net.Mail;
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("reports@moi.gov.sa");
mail.To.Add("gowri.utham@esolutionsroad.com");
mail.CC.Add("gowri.utham@gmail.com");
mail.Subject = "Trial Report - MOI Portal Registrations & Transactions - Daily Stats - " + DateTime.Now.ToString("dd/MM/yyyy");
mail.IsBodyHtml = true;
mail.Body = "<html><body>Dears,<br><br>Please find portal registration and transaction statistics in detail as of <b> " + DateTime.Now.ToString("dd/MM/yyyy") + " </b>.<br><br>Thanks,<br><br>Biz Dashboard Opz Team.</body></html>";
System.Net.Mail.Attachment attachment1;
attachment1 = new System.Net.Mail.Attachment(@"C:\Users\gowri\Desktop\StatisticsReport.pdf");
mail.Attachments.Add(attachment1);
System.Net.Mail.Attachment attachment2;
attachment2 = new System.Net.Mail.Attachment(@"C:\Users\gowri\Desktop\TransactionReport.pdf");
mail.Attachments.Add(attachment2);
SmtpServer.Credentials = new System.Net.NetworkCredential("user name", "password");
SmtpServer.Port = 25;
SmtpServer.Host = "xxx.xxx.xxx.xxx";
SmtpServer.Send(mail);
Response.Write("Mail has been Send");
Response.Write(DateTime.Now.ToString("dd/MM/yyyy HH:mm:s"));
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
No comments:
Post a Comment