Search code examples
c#smtpsmtpclient

C# SmtpClient connecting to A2 hosting email


I am having a very hard time trying to send an email through an a2 hosting account. I know the code is correct as I have the same code sending emails through the Google SMTP. I was wondering if anyone had any experience or examples using a2 hosting email and SMTP c#. I've read through their documentation and it states to use [email protected] for the username and then your password. For the server you can use the full domain name or the server name. For the port it says 587 or 465. I have tried a combination of all of these things and have not been able to connect. I keep getting this exception

"Unable to read data from the transport connection: net_io_connectionclosed."

Thank you for any help.

Below is an example of the code I am using.

SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("[email protected]");
NetworkCredential myCred = new NetworkCredential(
 "[email protected]", "mypassword");

smtpClient.Host = "mydomain.a2hosted.com";
//smtpClient.Credentials = myCred;
smtpClient.Port = 587;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = false;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Credentials = myCred;
message.From = fromAddress;
message.Subject = "your subject";
//Set IsBodyHtml to true means you can send HTML email.
message.IsBodyHtml = true;
message.Body = "<h1>your message body</h1>";
message.To.Add("[email protected]");

smtpClient.Send(message);

Solution

  • All in here.

    https://www.a2hosting.co.uk/kb/a2-hosting-products/windows-hosting/using-asp-net-to-send-e-mail-messages#C-example

    Replace domain.a2hosted.com with your own domain name. Replace [email protected] with the name of an e-mail account you created in Plesk. Replace password with the password for the e-mail account you specified in the previous step.

    From my config file.

    <mailSettings>
          <smtp from="[email protected]">
            <network enableSsl="false" 
    defaultCredentials="false" host="yourdomain" 
    password="yourpassword" port="25" 
    userName="youremailaddress" />
    </mailSettings>