0

Here I want to send mail using gmail smtp.But I shows error

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

on button click insted of sending mail.

html

<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox>
<asp:TextBox ID="txtfrompassword" runat="server"></asp:TextBox>
<asp:TextBox ID="txtto" runat="server"></asp:TextBox>
<asp:TextBox ID="txtbody" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

code behind

protected void Button1_Click(object sender, EventArgs e)
{
    MailMessage msg = new MailMessage(txtfrom.Text,txtto.Text);
    msg.Body = txtbody.Text;
    SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
    sc.Credentials = new NetworkCredential(txtfrom.Text, txtfrompassword.Text);
    sc.EnableSsl = true;
    sc.Send(msg);
    Response.Write("send");
}
Salah Akbari
  • 39,330
  • 10
  • 79
  • 109
sudipchand7139
  • 55
  • 2
  • 10
  • Possible duplicate of [mail sending with network credential as true in windows form not working](http://stackoverflow.com/questions/32475832/mail-sending-with-network-credential-as-true-in-windows-form-not-working) – Salah Akbari Jul 25 '16 at 11:02

2 Answers2

0

You can use port 25

 SmtpClient sc = new SmtpClient("smtp.gmail.com", 25);
Mostafiz
  • 7,243
  • 3
  • 28
  • 42
0

turn on this option

u can send mail using STMP

https://www.google.com/settings/security/lesssecureapps