Advertisement
aaand1

Untitled

Sep 9th, 2017
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. Issue happens when email is send from asp.net mvc 5 application hosted under iis/8.5
  2. Sample web.config:
  3. ...
  4. <system.net>
  5. <mailSettings>
  6. <smtp from="noreply@smart-payment.ru" deliveryMethod="Network">
  7. <network host="smtp.elasticemail.com" enableSsl="false" port="2525" userName="noreply@smart-payment.ru" password="d0774536-164a-4f59-b4bd-76511c50eb78" defaultCredentials="false" />
  8. </smtp>
  9. </mailSettings>
  10.  
  11. Steps to reproduce:
  12. 1. Configure <mailSettings> node within root asp.net Web.config
  13.  
  14. 2. Send email using System.Net.Mail.SmtpClient. Consider next sample code:
  15.  
  16. ```cs
  17. using System.Net.Mail;
  18. ...
  19. public class Mailer {
  20. public void SendMail(MailLetter message)
  21. {
  22. using (var smtpClient = new SmtpClient())
  23. using (var msg = new MailMessage
  24. {
  25. IsBodyHtml = true,
  26. Subject = "Some Subject",
  27. Body = "Some body",
  28. From = new MailAddress(message.From, message.FromDisplayName)
  29. })
  30. {
  31. msg.ReplyToList.Add(new MailAddress(string.IsNullOrWhiteSpace(message.ReplyTo) ? message.From : message.ReplyTo, message.FromDisplayName));
  32. foreach (var addr in message.To)
  33. msg.To.Add(new MailAddress(addr));
  34. smtpClient.Send(msg);
  35. }
  36. }
  37. ...
  38. }
  39. ```
  40. Actual result:
  41. Exception is thrown on `smtpClient.Send(msg)` invocation
  42.  
  43. ```
  44. 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
  45. at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
  46. at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
  47. ```
  48.  
  49. Expected result:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement