Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. System.Net.Mail problem

System.Net.Mail problem

Scheduled Pinned Locked Moved C#
helpcsharpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JustRonald
    wrote on last edited by
    #1

    Hi, I'm trying to create a function that will automaticly send me the errors of the application using the MailMessage function from the namespace: System.Net.Mail. This is the code I have now but for some reason it aint working. It gives me the following error (sorry it's in dutch): "Postbus niet beschrikbaar. Het serverantwoord is: 5.7.1 Unable to relay for email@company.nl"

    try
    {
    MailMessage message = new MailMessage();

    message.From = new MailAddress("info@company.nl", "Application AutoEmail", System.Text.Encoding.UTF8);
    message.To.Add(new MailAddress("email@company.nl"));
    message.Subject = "Application error";
    message.Body = "This is the content...";
    message.Priority = MailPriority.Normal;
    
    SmtpClient client = new SmtpClient();
    client.Host = "localhost";
    client.Port = 25;
    client.Send(message);
    
    MessageBox.Show("Your email has succesfully been send.", "Email send");
    

    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message, "Error");
    }

    What am I doing wrong?

    L 1 Reply Last reply
    0
    • J JustRonald

      Hi, I'm trying to create a function that will automaticly send me the errors of the application using the MailMessage function from the namespace: System.Net.Mail. This is the code I have now but for some reason it aint working. It gives me the following error (sorry it's in dutch): "Postbus niet beschrikbaar. Het serverantwoord is: 5.7.1 Unable to relay for email@company.nl"

      try
      {
      MailMessage message = new MailMessage();

      message.From = new MailAddress("info@company.nl", "Application AutoEmail", System.Text.Encoding.UTF8);
      message.To.Add(new MailAddress("email@company.nl"));
      message.Subject = "Application error";
      message.Body = "This is the content...";
      message.Priority = MailPriority.Normal;
      
      SmtpClient client = new SmtpClient();
      client.Host = "localhost";
      client.Port = 25;
      client.Send(message);
      
      MessageBox.Show("Your email has succesfully been send.", "Email send");
      

      }
      catch (Exception ex)
      {
      MessageBox.Show(ex.Message, "Error");
      }

      What am I doing wrong?

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Your local SMTP server is not set up correctly.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 3 out now

      J 1 Reply Last reply
      0
      • L leppie

        Your local SMTP server is not set up correctly.

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 3 out now

        J Offline
        J Offline
        JustRonald
        wrote on last edited by
        #3

        Thank you! I changed "localhost" to "ExchangeServer" (our local mail server) and it worked. But if the application is running on a computer outside our network, the SMTP host will be different. So is there a way to determine the SMTP host address/name of the current computer/user?

        B 1 Reply Last reply
        0
        • J JustRonald

          Thank you! I changed "localhost" to "ExchangeServer" (our local mail server) and it worked. But if the application is running on a computer outside our network, the SMTP host will be different. So is there a way to determine the SMTP host address/name of the current computer/user?

          B Offline
          B Offline
          Bert delaVega
          wrote on last edited by
          #4

          If the Exchange server is internet accessible (a fully qualified domain name), then just use that instead so that if you're deploying outside of your LAN, it can still be reached. If not, then you might need to allow for user configuration to specify the SMTP server name or address.

          J 1 Reply Last reply
          0
          • B Bert delaVega

            If the Exchange server is internet accessible (a fully qualified domain name), then just use that instead so that if you're deploying outside of your LAN, it can still be reached. If not, then you might need to allow for user configuration to specify the SMTP server name or address.

            J Offline
            J Offline
            JustRonald
            wrote on last edited by
            #5

            Ah ok... But it's not possible to get the hostname/address from the SMTP server in C#?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups