0
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();

message.From = new MailAddress("myname@mycompany.com.sg");
message.To.Add(new MailAddress("myname@hotmail.com"));
message.Subject = "In need of help";
message.Body = "Good morning" + txt_name;";
smtp.Port = 465;
smtp.Host = "mail.mycompany.com.sg";
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("myname@mycompany.com.sg", "xxxxxxxxx");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(message);
MessageBox.Show("email sent");

I have an email code which works when sending email to the same domain but is unable to send to others email platform such as gmail and hotmail. I am receiving this error on my windows

"err: failure sending mail.".

Any help would be greatly appreciated

EGS
  • 55
  • 1
  • 7
  • 1
    Good question but... if you post it in google, you may see the answer. lt is probably related you your server and not to your code – T.S. Sep 26 '17 at 02:09
  • Have you checked that you can use this SMTP server to e-mail those addresses from within a mail client (e.g. Outlook, Thunderbird, etc.)? The code looks fine. – ProgrammingLlama Sep 26 '17 at 02:19
  • @T.S. Thanks. May i know what do i have to configure in my server? Sorry fairly new to c#. – EGS Sep 26 '17 at 02:19
  • 1
    Here we solve programming questions, not server config – T.S. Sep 26 '17 at 02:21
  • @john yes I have tried sending emails to test them out. But really clueless on why is it not working. – EGS Sep 26 '17 at 02:22
  • @EGS You don't need to do anything special to get your server to work with C#. I'd suggest that the server is limiting the addresses you can send e-mail to using SMTP (in general) and that you would see the same issue in third party mail clients, such as Outlook or Thunderbird. – ProgrammingLlama Sep 26 '17 at 02:23
  • if i am not wrong, i think its the same problem of this question: https://stackoverflow.com/questions/9201239/send-e-mail-via-smtp-using-c-sharp – Katt Sep 26 '17 at 03:10

1 Answers1

0

I would like to suggest an alternative for you EGS. To test to see if the problem is a config issue on the SMTP server that you are using, sign up for an Azure Account and inside the Azure account, sign up for a SENDGRID account. The service will assign you a username and password and server information that will work with your above SMTP code. This test will confirm that your code is working perfectly as it does look right.

Once you have confirmed that it is not your code, you have enough information to approach the IT guy who runs the server to fix the issue, or just use SendGrid until your IT department blocks that as well.

For what its worth, you issue is most certainly a config issue, likely email to those domain names is blocked. This is a common practice to prevent employees from emailing sensitive documents to themselves (since many, if not most people now use either gmail or hotmail for their personal email).

Wizengamot
  • 150
  • 1
  • 7