I'm using ASP.Net (MVC) to send an email from a website.
When I have tried to send it in debug mode, I have the following error:
System.Net.Mail.SmtpException: Server does not support secure connections. at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result) at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result)
at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at BL.Controllers.HomeController.<TryMe>d__5.MoveNext() in D:\Main\01. BL\01. Projects\03. Website\02. Code\BL\BL\BL\Controllers\HomeController.cs:line 186
After publishing it, I have the following error:
The remote certificate is invalid according to the validation procedure.
I have asked the host provider (Hostgator) to help me and he told me that the error occurred due to wrong configuration in my script, but he can't detect what is it exactly as his development skills is limited.
This is the Configuration that I have used in web.config file:
if (model != null && validData)
{
var receiverEmail = new MailAddress("project@b-l.group");
var subject = "Online Service";
var body = GetMailBody(model);
System.Net.Mail.SmtpException: Server does not support secure connections.
You mixing SSL with Port 25, for SSL usually port is 587, so you have 2 choices
a) Change to port 587, or check provider to use proper port
b) Change enableSsl to false and leave port 25
On remarks you find
"The
System.Net.Mail.SmtpClient class only supports the SMTP Service Extension for Secure SMTP over Transport Layer Security as defined in RFC 3207"
I suggest you try Mailkit, as proposed in in System.Net.Mail.Smtpclient above
Member
1 Points
12 Posts
Send Email (SMTP)
Apr 17, 2019 09:37 AM|Elgamily|LINK
I'm using ASP.Net (MVC) to send an email from a website.
When I have tried to send it in debug mode, I have the following error:
System.Net.Mail.SmtpException: Server does not support secure connections. at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result) at System.Net.Mail.SmtpTransport.EndGetConnection(IAsyncResult result) at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at BL.Controllers.HomeController.<TryMe>d__5.MoveNext() in D:\Main\01. BL\01. Projects\03. Website\02. Code\BL\BL\BL\Controllers\HomeController.cs:line 186
After publishing it, I have the following error:
The remote certificate is invalid according to the validation procedure.
I have asked the host provider (Hostgator) to help me and he told me that the error occurred due to wrong configuration in my script, but he can't detect what is it exactly as his development skills is limited.
This is the Configuration that I have used in web.config file:
<mailSettings>
<smtp from="mail@b-l.group">
<network host="hgws28.win.hostgator.com" enableSsl="true" port="25"
userName="***" password="***"/>
</smtp>
</mailSettings>
And this is the Code that I have used in my Controller file:
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> TryMe(EmailFormModel model)
{
try
{
bool validData = IsValidData(model);
if (model != null && validData)
{
var receiverEmail = new MailAddress("project@b-l.group");
var subject = "Online Service";
var body = GetMailBody(model);
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
{
return true;
};
MailMessage message = new MailMessage();
message.To.Add(receiverEmail);
message.Subject = subject;
message.Body = body;
using (SmtpClient smtp = new SmtpClient())
{
await smtp.SendMailAsync(message);
ViewBag.Verified = "Data Sent!";
}
return View(model);
}
else
{
ViewBag.Warning = "Fill missed data!";
}
}
catch (Exception ex)
{
ViewBag.Warning = ex.ToString();
}
return View(model);
}
What is the problem in my script?
Member
749 Points
527 Posts
Re: Send Email (SMTP)
Apr 17, 2019 12:42 PM|jzero|LINK
You mixing SSL with Port 25, for SSL usually port is 587, so you have 2 choices
a) Change to port 587, or check provider to use proper port
b) Change enableSsl to false and leave port 25
Member
1 Points
12 Posts
Re: Send Email (SMTP)
Apr 17, 2019 01:12 PM|Elgamily|LINK
a) For the first solution, I have asked my provider (Hostgator) and he said that it is port 25 not 587
b) For the second solution, I have changed enableSsl to false and the same error exist.
Member
749 Points
527 Posts
Re: Send Email (SMTP)
Apr 17, 2019 09:19 PM|jzero|LINK
It´s been a long time I used SmtpClass with/without web.config settings.
But I think found why you getting System.Net.Mail.SmtpException: Server does not support secure connections.
Here you find more about https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/network/network-element-network-settings
On remarks you find
"The System.Net.Mail.SmtpClient class only supports the SMTP Service Extension for Secure SMTP over Transport Layer Security as defined in RFC 3207"
I suggest you try Mailkit, as proposed in in System.Net.Mail.Smtpclient above