Base solution for your next web application
Open Closed

RESOLVED: Sending emails on hosted application - Issue #2325


User avatar
0
exlnt created

I have deployed my ABP application to my hosting providers site. I have updated the email settings as needed for my hosting provider. The test email is working fine for email addresses on my domain. However, when I try to send out emails to any other domain, I keep getting the error below.

System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: Authentication is required for relay
   at System.Net.Mail.SendMailAsyncResult.End(IAsyncResult result)
   at System.Net.Mail.SmtpTransport.EndSendMail(IAsyncResult result)
   at System.Net.Mail.SmtpClient.SendMailCallback(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 Abp.Net.Mail.Smtp.SmtpEmailSender.d__3.MoveNext()
--- 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 Abp.Net.Mail.EmailSenderBase.d__6.MoveNext()
--- 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 Abp.Net.Mail.EmailSenderBase.d__4.MoveNext()
--- 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 Abp.Net.Mail.EmailSenderBase.d__2.MoveNext()
--- 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 Configuration.Host.HostSettingsAppService.d__21.Mo...

I opened a ticket with my hosting provider's support team. They have replied with the below response.

Yes, I know it works from your domain name because that is sent internally. I tested that, and it works fine. In order to relay out, you need to authenticate (i.e. supply username and password), or our mail servers won't relay it out (we don't allow unauthenticated users to send messages out because of spammers which get our mail servers blacklisted). I could probably place a test script in your account to prove to you that it's working, but that's not the problem. The problem is that your CMS (ASPNetZero) is not authenticating correctly, but I don't know where the code is to send email so I can't verify that's the problem.

I searched on the forum for other postings on the issue and found some of the email code. However I could not find the code where the credentials are getting used. Can you help me resolve this issue? Thanks!


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Email is sent via this class <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/f10fa5205c780bcc27adfe38aaae631f412eb7df/src/Abp/Net/Mail/Smtp/SmtpEmailSender.cs">https://github.com/aspnetboilerplate/as ... lSender.cs</a>.

    This is a really simple .net email sending code.

    Can you try to create a simple console application and then copy code in this class and set all settings (like host, port, username, password) manually in your code and try to run this console app on your hosting server and see if it sends email or not ?

    When you provide username & password on your settings, ABP uses the here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/f10fa5205c780bcc27adfe38aaae631f412eb7df/src/Abp/Net/Mail/Smtp/SmtpEmailSender.cs#L52">https://github.com/aspnetboilerplate/as ... der.cs#L52</a>.

    It just includes domain setting if you also specify it.

    As a last option, we can also take a look at this problem if you give us temporary access to your hosting server and your email credentials.

    Thanks.

  • User Avatar
    0
    exlnt created

    The hosting provider actually setup a simple ASPX page(within my domain) with the C# code below and it works just fine. This sends emails to any address.

    protected void sendEmailButton_Click(object sender, EventArgs e)
        {
            MailMessage newMessage = new MailMessage();
            newMessage.From = new MailAddress(fromTextBox.Text);
            newMessage.To.Add(toTextBox.Text);
            newMessage.Subject = subjectTextBox.Text;
            newMessage.Body = messageBodyTextBox.Text;
    
            SmtpClient smtp = new SmtpClient("mail.mydomain.com", 25);
            NetworkCredential Credentials = new NetworkCredential("[email protected]", "xxxxx");
            smtp.Credentials = Credentials;
            smtp.Send(newMessage);
    
            messageStatusLabel.Text = "Email sent";
        }
    
  • User Avatar
    0
    exlnt created

    Ok issue is resolved now!

    The hosting team provided me with updated SMTP host name. Plus I had to remove the domain name from the ABP settings page to make it work. But emails are now going out. Thanks!

  • User Avatar
    0
    ismcagdas created
    Support Team

    I'm glad that it is solved :)