Send mail in c#

Manna
Posted by Manna under C# category on | Points: 40 | Views : 1456
// using this code in send mail button Onclick event

string username = //your name
string answer = null;
string mail = null;


MailMessage msg = new MailMessage();
msg.From = new MailAddress("...."); //from mail id
msg.To.Add(".."); //to mail id
msg.Subject = "sample test";
msg.Body = "UserName:" + username + ";
SmtpClient smtp = new SmtpClient("smtp.gmail.com");
smtp.EnableSsl = true;
smtp.Port = 25; // your smtp port number here
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("//user mail id", "//user password");

try
{
smtp.UseDefaultCredentials = false;
smtp.Credentials = SMTPUserInfo;
smtp.Send(msg);
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Alert", "alert('Your Password has been sent to your Email id')", true);
}
catch (Exception exe)
{
Response.Write(exe.Message.ToString());
}

Comments or Responses

Login to post response