Saturday, May 15, 2010

Send Mail in C#

using System.Net.Mail;

MailMessage objMessage = new MailMessage();

objMessage.Bcc.Add(dicInputs["Bcc"].ToString().Trim());
objMessage.From = new MailAddress(dicInputs["From"].ToString().Trim());
objMessage.To.Add(dicInputs["To"].ToString().Trim());
objMessage.Subject = dicInputs["Subject"].ToString().Trim();
objMessage.Body = dicInputs["Message"].ToString().Trim();

string[] sAttachments = null;

sAttachments = dicInputs["Attachments"].ToString().Split(',');

for (int intLoop = 0; intLoop <= sAttachments.GetUpperBound(0); intLoop++)
{
strLogOut = strLogOut + "Adding attachment '" + sAttachments[intLoop] + "'";
objMessage.Attachments.Add(new Attachment(sAttachments[intLoop]));
}


SmtpClient objClient = new SmtpClient();
objClient.Host = "";
objClient.Send(objMessage);

No comments:

Post a Comment