Failure sending mail

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pb2000
    New Member
    • Apr 2010
    • 13

    Failure sending mail

    Hello,

    Example is simple, shown on many forums, but not working.
    Code:
            MailMessage mail = new MailMessage();
            mail.To.Add("add1@gmail.com");
            mail.From = new MailAddress("add2@gmail.com");
            mail.Subject = "Test Email";
            mail.Body = "Hello";
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "localhost";
            smtp.Send(mail);
    On last line I obtain exception: "Failure sending mail".

    Anyway, Is it possible to send mail from my workstation (localhost)?
    If yes, then next problem occur - Mail.From Address. Shoud I provide sender address when I send from localhost?

    I tried examples from many sources. Unfortunatelly, results the same..

    Thank You for Your help.
    Paul
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Anyway, Is it possible to send mail from my workstation (localhost)?
    Sure... if your local workstation happens to be running an SMTP server.

    Since it probably isn't, you'll need to log onto your mail server using the same credentials your account in Outlook uses.

    Comment

    • liadmz
      New Member
      • Jul 2009
      • 32

      #3
      Originally posted by pb2000
      Hello,

      Example is simple, shown on many forums, but not working.
      Code:
              MailMessage mail = new MailMessage();
              mail.To.Add("add1@gmail.com");
              mail.From = new MailAddress("add2@gmail.com");
              mail.Subject = "Test Email";
              mail.Body = "Hello";
              SmtpClient smtp = new SmtpClient();
              smtp.Host = "localhost";
              smtp.Send(mail);
      On last line I obtain exception: "Failure sending mail".

      Anyway, Is it possible to send mail from my workstation (localhost)?
      If yes, then next problem occur - Mail.From Address. Shoud I provide sender address when I send from localhost?

      I tried examples from many sources. Unfortunatelly, results the same..

      Thank You for Your help.
      Paul
      Hi,

      First - You can send from "localhost" only if you have a smtp server installed on you station. (like FreeSMTP http://www.softstack.com/freesmtp.html).

      Second - In case you are using a remote SMTP server, lets say your ISP server.
      the "From" field is not always customizable.

      Some server are checking this field so the only "From" address is yours.
      from ex':
      if you are trying to connect to EarthLink server @ smtp.EarthLink. com
      and your user is "abc" then the only From address you can send from is:
      abc@earthlink.c om.

      this validation is usually been applied in mail server to prevent a fake sender.

      Hope this one help.

      Comment

      Working...