Thursday, February 4, 2010

SEND MAIL CLASSSSSSSSSSSSSS

public bool sendMail(string fromEmail, string toEmail, string mailSubject, string mailBody, MailFormat mailFormat, string

fromName, string toName)
{

try
{
if (fromName == "")
{
fromName = ConfigurationSettings.AppSettings["siteName"];
}
if (toName == "")
{
toName = toEmail;
}

MailMessage mail = new MailMessage();


mail.From = fromEmail;
mail.To = toEmail;
mail.Subject = mailSubject;
mail.BodyFormat = mailFormat;
mailBody += "";
mail.Body = mailBody;

SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SmtpServer"];
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",

ConfigurationSettings.AppSettings["sendemailusername"]);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",

ConfigurationSettings.AppSettings["sendemailpassword"]);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusing", 2);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserver",

ConfigurationSettings.AppSettings["SmtpServer"]);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 50);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);

//SmtpMail.SmtpServer = ConfigurationSettings.AppSettings["SmtpServer"];
////SmtpMail.SmtpServer.Insert(0, ConfigurationSettings.AppSettings["SmtpServer"].ToString());
// mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1);
// mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",

ConfigurationSettings.AppSettings["sendemailusername"]);
// mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",

ConfigurationSettings.AppSettings["sendemailpassword"]);


SmtpMail.Send(mail);

return true;
}
catch (Exception ex)
{
return false;
}
}

No comments:

Post a Comment