0
votes

I'm currently developing a website with a contact form. When the contact form is filled, an email must be sent to the person who have inserted this.

  • I'm using SMTP.

  • I'm using a shared email server.

My code looks like:

Task.Factory.StartNew(() =>
        {
            try
            {

                var smtpClient = new SmtpClient(SmtpHost, Port)
                {
                    DeliveryMethod = SmtpDeliveryMethod.Network,
                    UseDefaultCredentials = false,
                    Credentials = new NetworkCredential(From, Password)
                };

                using (smtpClient)
                {
                    using (MailMessage mailMessage = new MailMessage(From, From, "test", "test"))
                    {
                        smtpClient.Send(mailMessage);
                    }
                }
            }
            catch (Exception e)
            {

            }
        });

Everytime, I receive the following exception:

[System.Net.Mail.SmtpException] = {"Transaction failed. The server response is: 5.7.1 Recipient address rejected: Authentication required"} bij System.Net.Mail.RecipientCommand.CheckResponse(SmtpStatusCode statusCode, String response) bij System.Net.Mail.RecipientCommand.Send(SmtpConnection conn, String to, String& response) bij System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception) bij System.Net.Mail.SmtpClient.Send(MailMessage message)

In the code example I try to send an email to the same address as the sender. I already tried to send an email to my personal email accounts and this also fails.

Anyone knows what is going wrong here? I didn't found solutions on google/stackoverflow.

A few months ago, I developed a website with the same smtp host (but other domain) and this is still working fine..

Thank you.

2

2 Answers

0
votes

The only thing I saw in the web is problem with firewall so try to turn it of and try again to execute the application.

0
votes

Please check you mail configuration settings .Make sure your given port no is correct.