Sending email in ASP.net
-
Hi Please tell me how can we send email from an ASP.net application to a yahoo or gmail account? Thanks
to send an email from your application you have to ways: 1- use smtp server of your own 2- use one of the free smtp servers like gmail's accordingly after choosing your smtp there are two coding ways that goes as below: 1- add namespace of System.Net.mail; 2-in the click event of your [Send Email] button:
MailMessage mailmsg= new MailMessage();
mailmsg.From = new MailAddress("Your Email Address");
mailmsg.To.Add("Email of reciver");
mailmsg.Subject = "Your sybject";
mailmsg.Body = "The body of your mail (You can use html tags too";
mailmsg.IsBodyHtml = true;
SmtpClient smpt= new SmtpClient("127.0.0.1"); [if you are using your application in your own host]
smtp.Send(mailmsg);----------------------- Now if you don't have your own smtp and wanna use free one like google's do as below: 1- add the same name space 2- Code as below:
string subject = "Your Subject";
string from = "Your Gmail account having @gmail.com";
string rec = "reciver email";
string body = "The mail body.";
MailMessage mail = new MailMessage(from, rec);
mail.IsBodyHtml = true;
mail.SubjectEncoding = System.Text.UnicodeEncoding.UTF8;
mail.Subject = subject;
mail.Body = body;
SmtpClient sm = new SmtpClient();
System.Net.NetworkCredential me = new System.Net.NetworkCredential();
me.UserName = "your gmail username";
me.Password = "your gmail password";
sm.UseDefaultCredentials = false;
sm.Credentials = me;
sm.Host = "smtp.gmail.com";
sm.Port = 587;
sm.EnableSsl = true;
sm.Send(mail);hope it works
Proper Prepration Prevents Poor Performance! h
-
Hi Please tell me how can we send email from an ASP.net application to a yahoo or gmail account? Thanks
I wrote an article on how to use google. Because sending an email is 1 - trivial 2 - widely documented 3 - asked here often I based my tutorial on how to use google to search for how to send an email. Really 'send email C#' is all you needed, but I suggest you read the article anyhow.
Christian Graus Driven to the arms of OSX by Vista.