I am able to send email from a web page to the users in LOCAL HOST . But after hosting my website unable to send the mail.
Following is the error:
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. ha10sm40374374pbc.23 - gsmtp
public void SendMail(string ToMail, string subject, string Message)
{
// Gmail Address from where you send the mail
string fromAddress = "[email protected]";
// any address where the email will be sending
//string toAddress = ToMail;
//Password of your gmail address
const string fromPassword = "********";
// Passing the values and make a email formate to display
//string subject = subject;
string body = "\n\n"+Message;
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, ToMail, subject, body);
}Help me in solving this...
mahesh munnaPosted Sep 25, 2013, 4:46 AM
Posted Sep 25, 2013, 4:45 AM
This needs to be set, otherwise you will get this error.
Posted Sep 25, 2013, 4:41 AM
To configure SSL,
http://weblogs.asp.net/scottgu/archive/2007/04/06/tip-trick-enabling-ssl-on-iis7-using-self-signed-certificates.aspx
mahesh munnaPosted Sep 25, 2013, 4:39 AM
Posted Sep 25, 2013, 4:36 AM
Have you configured https in your website?
mahesh munnaPosted Sep 25, 2013, 4:30 AM
.net framework version: 3.5
IIS pool config details:
.NET Framework v2.0.50727
managed Pipeline mode:
Integrated
Posted Sep 25, 2013, 4:17 AM
IIS Version,
.net framework version, IIS pool config details?
mahesh munnaPosted Sep 25, 2013, 4:13 AM
Posted Sep 25, 2013, 3:45 AM
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("[email protected]", "mypwd"),
EnableSsl = true
};
client.Send("[email protected]", "[email protected]", "test", "testbody");
Console.WriteLine("Done");
Console.ReadLine();
}
}
}
mahesh munnaPosted Sep 25, 2013, 3:41 AM
Sanjeeb LenkaPosted Sep 25, 2013, 3:36 AM
try this code.
public void SendMail(string ToMail, string subject, string Message)
{
// Gmail Address from where you send the mail
string fromAddress = "[email protected]";
// any address where the email will be sending
//string toAddress = ToMail;
//Password of your gmail address
const string fromPassword = "********";
// Passing the values and make a email formate to display
//string subject = subject;
string body = "\n\n" + Message;
// smtp settings
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
// Passing values to smtp object
smtp.Send(fromAddress, ToMail, subject, body);
}