0

When I try to sendmail using asp.net I get the following error.

Error Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: Relaying not allowed

I have used the right credentials (through which we could access web mail)

I have configured the mail using Google Labs. Does this affect anyway?

MailMessage mailMsg = new MailMessage();

mailMsg.From = new MailAddress("info@thewebsite.com", "thewebsite.com");
mailMsg.To.Add(new MailAddress(ToAddress));
mailMsg.Subject = Subject;
mailMsg.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");



System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString
(System.Text.RegularExpressions.Regex.Replace(BodyText, @"<(.|\n)*?>", string.Empty), null, "text/plain");
System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(BodyText, null, "text/html");

mailMsg.AlternateViews.Add(plainView);
mailMsg.AlternateViews.Add(htmlView);


// Smtp configuration
SmtpClient smtp = new SmtpClient();

smtp.UseDefaultCredentials = true;

string smtphost = System.Configuration.ConfigurationManager.AppSettings["smtphost"].ToString();
int smtpport = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["smtpport"].ToString());


smtp.Host = smtphost; 
smtp.Port = smtpport;  


smtp.Credentials = new System.Net.NetworkCredential("info@thewebsite.com", "pwd1234");
Humayun Shabbir
  • 2,961
  • 4
  • 20
  • 33
Seb Thomas
  • 107
  • 1
  • 14
  • ANSWER: Refer: http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail/32336#32336 It worked – Seb Thomas Apr 09 '15 at 17:17

1 Answers1

0

I think that u must set the smtp.EnableSsl = true;

Sherif Ahmed
  • 1,896
  • 1
  • 19
  • 37
  • Now the issue becomes: Error Details: System.Net.Mail.SmtpException: Server does not support secure connections. at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) – Seb Thomas Apr 09 '15 at 16:31
  • Great http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail/32336#32336 worked. Thanks a lot! – Seb Thomas Apr 09 '15 at 17:18