Code
public void send(MailMsg msg, string[] attachments)
{
putlog("send:1");
MailMessage mail = new MailMessage();
mail.To = msg.MailTo;
mail.From = msg.MailFrom;
mail.Subject = msg.MailSubject;
mail.Body = msg.MailContent;
mail.BodyFormat = MailFormat.Html;
for (int i = 0; i < attachments.Length; i++)
{
putlog("send:1-" + (i + 1).ToString());
if (attachments[i] != null && attachments[i].ToString() != "")
{
putlog("send:1-" + (i + 1).ToString() + "-1");
MailAttachment attachment = new MailAttachment(attachments[i].ToString());
mail.Attachments.Add(attachment);
}
}
putlog("send:2");
//basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ConfigurationManager.AppSettings["UserName"]);
//set your password here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ConfigurationManager.AppSettings["UserPwd"]);
//ip of mail server
SmtpMail.SmtpServer = ConfigurationManager.AppSettings["mailServerIP"]; //"10.25.100.21"; //your real server goes here
SmtpMail.Send(mail);
}
public void send(MailMsg msg, string[] attachments)
{
putlog("send:1");
MailMessage mail = new MailMessage();
mail.To = msg.MailTo;
mail.From = msg.MailFrom;
mail.Subject = msg.MailSubject;
mail.Body = msg.MailContent;
mail.BodyFormat = MailFormat.Html;
for (int i = 0; i < attachments.Length; i++)
{
putlog("send:1-" + (i + 1).ToString());
if (attachments[i] != null && attachments[i].ToString() != "")
{
putlog("send:1-" + (i + 1).ToString() + "-1");
MailAttachment attachment = new MailAttachment(attachments[i].ToString());
mail.Attachments.Add(attachment);
}
}
putlog("send:2");
//basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", ConfigurationManager.AppSettings["UserName"]);
//set your password here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", ConfigurationManager.AppSettings["UserPwd"]);
//ip of mail server
SmtpMail.SmtpServer = ConfigurationManager.AppSettings["mailServerIP"]; //"10.25.100.21"; //your real server goes here
SmtpMail.Send(mail);
}