How to send a email from Website fields

Posted by Madhuri123 under ASP.NET on 8/24/2011 | Points: 10 | Views : 1006 | Status : [Member] | Replies : 3
Hi,
How to send a email from website


i write this code but it raises an errors
MailMessage mMailMessage = new MailMessage();
mMailMessage.To.Add(new MailAddress("mywebsite@gmail.com"));
mMailMessage.Subject = "Messaage";
mMailMessage.Body = "Name:" + TxtName.Text + "<BR>" + "Email:" + TXtEmail.Text + "<Br>" + "Phone:" + TxtMobile.Text + "<Br>" + "Adress :" + TxtAddress.Text + "<Br>" + "Enquiry: " + TxtEnquriy.Text + "BR";
mMailMessage.IsBodyHtml = true;
SmtpClient mSmtpClient = new SmtpClient();
mSmtpClient.Host = "smtp.gmail.com";
mSmtpClient.Port = 25;
mSmtpClient.Send(mMailMessage);
mMailMessage.Dispose();


Errors is The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. o2sm1227830yhl.43

can u please help me


Thanking u ,

madhuri




Responses

Posted by: Jpchoudhari on: 8/24/2011 [Member] Starter | Points: 25

Up
0
Down
specify from ID and use gmail credentials to send message.

mSmtpClient.UseDefaultCredentials = false;
mSmtpClient.Credentials = new System.Net.NetworkCredential(GmailID, GMailPassword);

Kind Regards,
Jay

Madhuri123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 8/25/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
see how i do it

MailMessage mm = new MailMessage();


SmtpClient smtp = new SmtpClient();

mm.From = new MailAddress(txtfrom.Text);

mm.To.Add(new MailAddress(txtto.Text));

// mm.To.Add(new MailAddress("moreemail@vuyiswa.co.za"));

mm.Subject = txtsubject.Text;

mm.Body = txtmessage.Text;

mm.IsBodyHtml = true;

smtp.Host = "smtp.gmail.com"; //You can add this in the webconfig

smtp.EnableSsl = true;

System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

NetworkCred.UserName = "vuyiswamb@gmail.com";

NetworkCred.Password = "wowOops";
smtp.UseDefaultCredentials = true;

smtp.Credentials = NetworkCred;

smtp.Port = 587; //this is Gmail port for e-mail

smtp.Send(mm);//send an e-mail

http://www.dotnetfunda.com/articles/article747-how-to-send-an-email-using-gmail-in-aspnet-.aspx

Thank you for posting at Dotnetfunda
[Administrator]

Madhuri123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Taanu51 on: 8/25/2011 [Member] Starter | Points: 25

Up
0
Down
Check out this link ..it may helps you

http://www.developerscode.com/2011/05/how-to-send-mail-using-aspnet-with-c.html


Tanisha Sayyad
.Net and Android Developer
INDIA(Andhra Pradesh)

Madhuri123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response