My code for sending mail is as follow
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click1(object sender, EventArgs e)
{
try
{
var fromaddress = "neena@gmail.com";
const string password = "aaaaaaaaaa";
var toaddress = TextBox2.Text;
string content;
content = "Hiii this is a example" + TextBox1.Text + " Thank you";
SmtpClient cl = new SmtpClient();
cl.Host = "smtp.gmail.com";
cl.Port = 587;
cl.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
cl.Credentials = new NetworkCredential(fromaddress, password);
cl.Send(fromaddress, toaddress, TextBox3.Text, content);
}
catch (Exception ex)
{
Response.Write(ex);
}
}
}
while running this code I am getting the error as
System.Net.Mail.SmtpException: 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. ab1sm20519532pbd.37 - gsmtp at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at System.Net.Mail.SmtpClient.Send(String from, String recipients, String subject, String body) at _Default.Button1_Click1(Object sender, EventArgs e) in f:\Training\Shopping\Default.aspx.cs:line 35
Reply
as fast as possible.
Thank you.