Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Issue happens when email is send from asp.net mvc 5 application hosted under iis/8.5
- Sample web.config:
- ...
- <system.net>
- <mailSettings>
- <smtp from="noreply@smart-payment.ru" deliveryMethod="Network">
- <network host="smtp.elasticemail.com" enableSsl="false" port="2525" userName="noreply@smart-payment.ru" password="d0774536-164a-4f59-b4bd-76511c50eb78" defaultCredentials="false" />
- </smtp>
- </mailSettings>
- Steps to reproduce:
- 1. Configure <mailSettings> node within root asp.net Web.config
- 2. Send email using System.Net.Mail.SmtpClient. Consider next sample code:
- ```cs
- using System.Net.Mail;
- ...
- public class Mailer {
- public void SendMail(MailLetter message)
- {
- using (var smtpClient = new SmtpClient())
- using (var msg = new MailMessage
- {
- IsBodyHtml = true,
- Subject = "Some Subject",
- Body = "Some body",
- From = new MailAddress(message.From, message.FromDisplayName)
- })
- {
- msg.ReplyToList.Add(new MailAddress(string.IsNullOrWhiteSpace(message.ReplyTo) ? message.From : message.ReplyTo, message.FromDisplayName));
- foreach (var addr in message.To)
- msg.To.Add(new MailAddress(addr));
- smtpClient.Send(msg);
- }
- }
- ...
- }
- ```
- Actual result:
- Exception is thrown on `smtpClient.Send(msg)` invocation
- ```
- System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions 188.165.1.80:2525
- at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
- at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
- ```
- Expected result:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement