Cannot send emails from C# code to any other domain but mine

Discussion in 'Email' started by nicom72, Jan 6, 2014.

  1. Hi,
    it seems I can send emails from my C# code only to email addresses hosted on my own domain, but not to other domains such as gmail or hotmail. Although I can send emails to any address from the SmarterMail web client on m05.internetmailserver.net and from Windows Live Mail (running on my local machine).
    I already went through all the forum entries and couldn't find a solution.
    My DNS configuration for mydomain.com that can be found at: https://cp.Winhost.com/domains/dns.aspx is:

    A Record for mail domain:

    Domain Name: mail.mydomain.com
    IP Address: AAA.BBB.CCC.DDD
    TTL: 3600

    When this IP address is copied-and-pasted in a web browser, it resolves to the web page login of SmarterMail on m05.internetmailserver.net

    There are two more A record for "mydomain.com" and "ftp.mydomain.com" which resolve to another IP address.


    MX Record:

    Domain Name: mail.mydomain.com
    Mail Server: m05.internetmailserver.net
    Priority: 10
    TTL: 3600

    No other MX Records exist.





    My C# test code (running from my local machine) is:


    // GIVEN
    // Works fine with "mydomain.com" email addresses such as "[email protected]"
    // Doesn't work with email addresses not hosted on "mydomain.com" such as gmail.com, hotmail.com, ...
    // Of course "mydomain.com" here is just a placeholder for the actual domain name which is embedded in my real code.
    var recipientEmailAddress = "[email protected]"; // In my actual code I use an existing email address, the one showed here is just a placeholder.

    var msg = new MailMessage
    {
    BodyEncoding = Encoding.Default,
    IsBodyHtml = true,
    Subject = emailSubject,
    Body = emailHtmlBody,
    From = new MailAddress("[email protected]"),
    };
    msg.To.Add(new MailAddress(recipientEmailAddress));

    var smtpClient = new SmtpClient("mail.mydomain.com") // nothing changes if I use the MX record to which mail.mydomain.com points to: m05.internetmailserver.net
    {
    Credentials = new NetworkCredential("[email protected]", "postmaster password"),
    DeliveryMethod = SmtpDeliveryMethod.Network,
    Port = 587, // also tried 25 and 465, but they don't seem to work
    Timeout = 60000,
    UseDefaultCredentials = false,
    };


    // WHEN-THEN
    smtpClient.Send(msg);





    Hangs for a few seconds then throws the exception:

    System.Net.Mail.SmtpFailedRecipientException: Mailbox not available. The server answered: <[email protected]> No such user here




    What am I doing wrong?

    Thank you for your help.
     
    Last edited by a moderator: Oct 14, 2015
  2. Elshadriel

    Elshadriel Winhost Staff

    You probably need to add a line of code for SMTP authentication. We provide sample code in this Knowledge Base article.
     
    Last edited by a moderator: Oct 14, 2015
  3. Hi,
    thank you for your reply. I followed your example in the Knowledge Base when I wrote the code I posted here.
    Isn't SMTP authentication taken care of by the NetworkCredential instance where I pass the postmaster username and password?
    Thank you.
     
  4. Elshadriel

    Elshadriel Winhost Staff

    You might also need to enable "Full Trust" as described in this Knowledge Base article. If this doesn't work, you can either message me your domain name so I can take a closer look or open up a support ticket regarding the problem. In either case, please provide us with a screen shot of the full error and a way to reproduce the problem. Everything looks ok so far.
     
    Last edited by a moderator: Oct 14, 2015
  5. I'm running a .Net 4.5 console application which will become a windows service on Azure, so I couldn't set the full trust level as mentioned in your KB. I found another way and now it's full trust.
    The problem remains, so I'm sending you a private message.
    Thank you for your time and effort.
     
  6. Hi I am having the same problem on www.appsbydaniel.com, what was the resolution of this please?
     
  7. Hi Michael, thanks, but as it happens it was a coding error on my part, so it is resolved
     
    Michael and Elshadriel like this.

Share This Page