2

I desperately need help solving this issue. How can I get my deployed app to send emails to any address via SMTP?

I am developing a web-based sales-tracking application in Visual Studio 2015 (ASP.NET MVC). The site will be hosted on an Arvixe BusinessClass for Windows shared server. The domain of the server is mydomain.com, however this domain is actually hosted by one.com, which also provides mydomain.com email.

One of the functions of the site is to inform the line manager when a user reports a sale. The line manager is to be informed via email. The email account I am trying to send from is provided by one.com.

Using System.Net.Mail.MailMessage and sending via SmtpClient, trhe following code works in my development environment (Windows 10 pro) but not deployed (deployed on Arvixe BusinessClass for Windows shared server environment):

MailMessage message = new MailMessage();
message.To.Add("recipient@mydomain.com");
message.From = new MailAddress("sender@mydomain.com", "sender@mydomain.com");
message.IsBodyHtml = true;
message.Subject = "Subject";
message.Body = "Body<br />";
SmtpClient client = new SmtpClient();
client.DeliveryFormat = SmtpDeliveryFormat.SevenBit;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "send.one.com";
client.Port = 587;
client.UseSSL = true;
client.Credentials = new NetworkCredential("sender@mydomain.com", "***");
client.Send(message);

On my Arvixe server I get the error:

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

Using this code I have also tried ports 465 and 25, with SSL set to true and false, and also host "mailout.one.com", without success.

I gave up and tried using MailKit with the following code:

MimeMessage message = new MimeMessage();
message.To.Add(new MailboxAddress("recipient@mydomain.com"));
message.From.Add(new MailboxAddress("sender@mydomain.com", "sender@mydomain.com"));
var bodyBuilder = new BodyBuilder();
bodyBuilder.HtmlBody = "htmlbody<br />";
bodyBuilder.TextBody = "textbody";
message.Body = bodyBuilder.ToMessageBody();
message.Subject = "Subject";

using (var client = new SmtpClient())
{
    client.ServerCertificateValidationCallback = (s, c, h, e) => true;
    client.Connect("send.one.com", 587, MailKit.Security.SecureSocketOptions.StartTls);  
    client.Authenticate("sender@mydomain.com", "***");
    client.Send(message);
    client.Disconnect(true);
}

Again it works in my development environment, but not in production. Here I get the error:

    "The operation is not allowed on non-connected sockets".

Of note, both solutions work in deployed environment if I change the host to 127.0.0.1 and add an example@mydomain.com email account and connected user account in Arvixe, but only for external email addresses. Addresses ending in mydomain.com obviously get rerouted back to the server itself, as the server's domain is mydomain.com, but as the email provider is one.com and not the Arvixe server, the email doesn't get through.

Other things I have tried without success:

-Setting the SPF record for mydomain.com to include my server address, and my server IP address.

-Using an Office365 account on a different domain to send from (host "smtp.office365.com")

I desperately need help solving this issue. How can I get my deployed app to send emails to any address via SMTP?

Arvixe/One.com suggestions (from support tickets and live chat):

  1. SMTP Authentication must be used.
  2. The local mail server, or localhost must be used to send email via web script. (try xxx.win.arvixe.com, localhost, or 127.0.0.1 - port 25 or 26, or xxxsecuremail.win.arvixe.com - port 465 for secure mail)
  3. The FROM email address, and SMTP Authentication email address, must be a local user on the local server.

If you have your own remote email server and intend to send emails via web script to email addresses that are local to your domain, then that mail domain needs to be removed from the local server (we have to do this) and you will have to use an account from another domain local to the server to send mail from. Otherwise any email going to the local domain will be delivered locally and not to your remote server.

  • you are using the wrong host. Host should be one of their email server address not your domain name. you should ask their support to see what the address is – Steve Dec 11 '18 at 17:43
  • @Steve, thanks for the assisstance. As per one.com's advice, "send.one.com" or "mailout.one.com" (which is not my domain) is their email server for sending externally via smtp. I have had success sending email with the host "send.one.com" in my development environment. – Jimmy Brick Dec 11 '18 at 17:50
  • again, this is something you should ask their support. Possible factors are: firewall, trust level, dns, port forwarding ect. – Steve Dec 11 '18 at 17:55
  • @Steve, sorry I should probably have mentioned in the post; during the past week I have opened three tickets with Arvixe and one with one.com. I also spent 2 hours last night in live chat with both Arvixe and one.com. None of their suggestions have worked, however I'll add their suggestions to the bottom of the post. – Jimmy Brick Dec 11 '18 at 18:10
  • It doesn't seem like you are following their advice about using one of the hosts that they suggested to connect to. You are trying to connect to `"send.one.com"` when they specifically told you to connect to `xxx.win.arvixe.com, localhost, or 127.0.0.1 - port 25 or 26, or xxxsecuremail.win.arvixe.com - port 465 for secure mail` – jstedfast Dec 11 '18 at 21:59
  • Thanks for the help @jstedfast. As mentioned in the post, I tried 127.0.0.1 (which is xxx.win.arvixe.com, i.e. the host of the site). It did actuallty work, but only for emails with domains other than my domain. As the domain of the site host is the same as my email address, when I try to send to emails on my domain, the emails are looped back to the site host, and not pushed through to the email providers mail server. With this function the most important element is to send emails to addresses on my own domain. – Jimmy Brick Dec 11 '18 at 22:18
  • That sounds like a DNS problem to me... – jstedfast Dec 11 '18 at 22:19

0 Answers0