MailMessage l_objMessage = new MailMessage();
MailAddress FromMailAddress = new MailAddress("mail server");
l_objMessage.From = FromMailAddress;
string[] Toaddresses = txtEmailTo.Text.Split(new char[] { ';', ',' });
foreach (string Torecip in Toaddresses)
{
l_objMessage.To.Add(Torecip);
}
if (txtEmailCC.Text != "")
{
string[] CCaddresses = txtEmailCC.Text.Split(new char[] { ';', ',' });
foreach (string CCrecip in CCaddresses)
{
l_objMessage.CC.Add(CCrecip);
}
}
if (txtEmailBCC.Text != "")
{
string[] BCCaddresses = txtEmailBCC.Text.Split(new char[] { ';', ',' });
foreach (string BCCrecip in BCCaddresses)
{
l_objMessage.Bcc.Add(BCCrecip);
}
}
l_objMessage.Subject = txtEmailSubject.Text;
l_objMessage.Body = RadEditor1.Content;
l_objMessage.IsBodyHtml = true;
System.Net.Mail.Attachment attachment = null;
if (FileID != "")
{
attachment = new System.Net.Mail.Attachment(Server.MapPath("../ExportFiles/" + FileID.ToString() + ".csv")); //create the attachment
l_objMessage.Attachments.Add(attachment);
}
SmtpClient MailSender = new SmtpClient("smtp.gmail.com");
NetworkCredential mycred = new NetworkCredential("mail server","Alias Name");
MailSender.Credentials = mycred;
MailSender.Port = 587;
MailSender.EnableSsl = true;
MailSender.Send(l_objMessage);
No comments:
Post a Comment