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.
You probably need to add a line of code for SMTP authentication. We provide sample code in this Knowledge Base article.
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.
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.
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.
Assuming you've tried SMTP authentication and Full Trust as discussed earlier, you might want to open a support ticket and we"ll take a look.