Thursday, February 21, 2008

Creating mail Class Using C# dotnet (2005VS)

public bool SendEmailUserRegistration(string strEmailFrom, string strEmailTo, string strMailSubject ,string strMailBody,string username,string password)
{
try
{
SmtpClient smtp = new SmtpClient(System.Configuration.ConfigurationSettings.AppSettings["SmtpServer"]);
smtp.Host = "127.0.0.1";
smtp.Port = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["Port"]);

MailMessage message = new MailMessage(strEmailFrom, strEmailTo);
message.From = new MailAddress(strEmailFrom,"Admin");
message.Subject = System.Configuration.ConfigurationSettings.AppSettings["MessageSubjectUserCreation"].ToString();
message.IsBodyHtml = true;
message.Body = System.Configuration.ConfigurationSettings.AppSettings["MessageBodyUserCreation"].ToString() +"User Name: " + username+ "
" +"Password: "+ password;

//smtp.Send(strEmailFrom, "Name@Company.com", "test subject", strMailBody);
smtp.Send(message);
return true;
}
catch (Exception ex)
{
return false;
}
}

No comments: