locked
Unable to send mail through Azure hosting environment through System.Net.Mail RRS feed

  • Question

  • User1052662409 posted

    Hi All,

    In my web application I am sending mail using using System.Net.Mail; 

    In my local machine and in my personal server mailing is working fine, but when I hosted it on Azure the mail doesn't work.

    Please suggest

    Friday, March 1, 2019 11:46 AM

Answers

  • User283571144 posted

    Hi demoninside9,

    Could you please tell me which azure service you have used? Azure web app or Azure VM?

    If you use azure web app, you could refer to below article to know how to remote debug with the Azure App service.

    https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugging-azure?view=vs-2017#remote_debug_azure_app_service 

    If you use azure VM, you could refer to below article to know how to remote debug the Azure VM.

    https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugging-azure?view=vs-2017#remote_debug_azure_vm 

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 4, 2019 2:06 AM
  • User1052662409 posted

    I get the message "sent".

    Some how it works, but mail doesn't come. Then I found that my MailJet account was not verified. I needed to verify it first.

    Thanks 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 4, 2019 8:03 AM

All replies

  • User753101303 posted

    Hi,

    And your mail server is supposed to be reachable from the internet ?

    When  an error happens it's best to get and give full details so that we don't have to guess which problem you actually SEE among all those that could happen.

    A typical error message looks like (the root cause being at the bottom) :

     System.Net.Mail.SmtpException was caught
      Message=Failure sending mail.
      Source=System
      StackTrace:
           at System.Net.Mail.SmtpClient.Send(MailMessage message)
           at xxxx.Sendbtn_Click(Object sender, EventArgs e) in xxx.aspx.cs:line 488
      InnerException: System.Net.WebException
           Message=Unable to connect to the remote server
           Source=System
           StackTrace:
                at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
                at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
                at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
                at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
                at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
                at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
                at System.Net.Mail.SmtpClient.GetConnection()
                at System.Net.Mail.SmtpClient.Send(MailMessage message)
           InnerException: System.Net.Sockets.SocketException
                Message=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond x.x.x.x:25
                Source=System
                ErrorCode=10060
                NativeErrorCode=10060
                StackTrace:
                     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, Int32 timeout, Exception& exception)
                InnerException: 

    Friday, March 1, 2019 11:55 AM
  • User1052662409 posted
    Sir, It doesn't show any error. Even I put a WebMsg box in catch block.

    How can I debug it in Azure hosted environment?

    Please suggest.

    Thanks
    Friday, March 1, 2019 2:17 PM
  • User283571144 posted

    Hi demoninside9,

    Could you please tell me which azure service you have used? Azure web app or Azure VM?

    If you use azure web app, you could refer to below article to know how to remote debug with the Azure App service.

    https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugging-azure?view=vs-2017#remote_debug_azure_app_service 

    If you use azure VM, you could refer to below article to know how to remote debug the Azure VM.

    https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugging-azure?view=vs-2017#remote_debug_azure_vm 

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 4, 2019 2:06 AM
  • User1052662409 posted

    Could you please tell me which azure service you have used? Azure web app or Azure VM?

    Sir.. it is Azure Web App

    Anyways I found a email service in azure whic is Mail Jet. I coded they way they suggested for sending email.

    Code is running fine and executes perfectly. But the strange this is that, email doesn't come in inbox. even I checked span/junk there is no email.

      MailMessage msg = new MailMessage();
    
                msg.From = new System.Net.Mail.MailAddress("********", "Test");
                msg.To.Add(new System.Net.Mail.MailAddress("********", "Test1"));
    
                msg.Subject = "Mail from Azure and MailJet!";
                msg.Body = "This is just a simple test message!";
    
                SmtpClient client = new SmtpClient("in.mailjet.com", 587);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.EnableSsl = true;
                client.UseDefaultCredentials = false;
                client.Credentials = new System.Net.NetworkCredential("*************", "*************");
    
                client.Send(msg);
                WebMsgBox.Show("sent");

    I get the message "sent".

    Please suggest.

    Monday, March 4, 2019 6:44 AM
  • User1052662409 posted

    I get the message "sent".

    Some how it works, but mail doesn't come. Then I found that my MailJet account was not verified. I needed to verify it first.

    Thanks 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 4, 2019 8:03 AM