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. Error while using System.Net.Mail.SmtpClient to send mail

Error while using System.Net.Mail.SmtpClient to send mail

Scheduled Pinned Locked Moved C#
csharpcomhelpquestionannouncement
4 Posts 2 Posters 1 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.
  • A Offline
    A Offline
    A M SOMAN
    wrote on last edited by
    #1

    I am trying to send a mail through my console application which is in .Net 2.0 with C# language. I am using the class System.Net.Mail.SmtpClient to send a mail. This was decided because the older version of this class System.Web.Mail.SmtpMail is now totally obsolete. But I get an error message as "Failure sending mail." when I run my code. I tried to resolve this by following: 1. Tried pinging the address from command prompt. It shows reply. 2. Assigned port number as number 25. Doesn't work. Gives same error. Following is my code FromEmail = "anil.soman@xyz.com"; strEmailAddre = "somebody@xyz.com"; strSubject = "some subject"; strBody = "some text for body"; System.Net.Mail.SmtpClient SMTPClient = new System.Net.Mail.SmtpClient(); SMTPClient.Host = "smtpservername"; SMTPClient.Port = 25; SMTPClient.Send(FromEmail, strEmailAddre, strSubject, strBody); What could be the reason for this? Any suggessions? Thanks in advance. Regards, Anil

    A 1 Reply Last reply
    0
    • A A M SOMAN

      I am trying to send a mail through my console application which is in .Net 2.0 with C# language. I am using the class System.Net.Mail.SmtpClient to send a mail. This was decided because the older version of this class System.Web.Mail.SmtpMail is now totally obsolete. But I get an error message as "Failure sending mail." when I run my code. I tried to resolve this by following: 1. Tried pinging the address from command prompt. It shows reply. 2. Assigned port number as number 25. Doesn't work. Gives same error. Following is my code FromEmail = "anil.soman@xyz.com"; strEmailAddre = "somebody@xyz.com"; strSubject = "some subject"; strBody = "some text for body"; System.Net.Mail.SmtpClient SMTPClient = new System.Net.Mail.SmtpClient(); SMTPClient.Host = "smtpservername"; SMTPClient.Port = 25; SMTPClient.Send(FromEmail, strEmailAddre, strSubject, strBody); What could be the reason for this? Any suggessions? Thanks in advance. Regards, Anil

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #2

      A M SOMAN wrote:

      Any suggessions?

      1. Create an MailMessage object. I know it's the same thing but...you can give it a try. 2) Check the port number, because usually it's 25 but it can differ from one server to another 3) Try configuring an email client like Outlook and if that doesn't also work....it's from somewhere else than your App Hope it helps.

      Do your best to be the best

      A 1 Reply Last reply
      0
      • A Andrei Ungureanu

        A M SOMAN wrote:

        Any suggessions?

        1. Create an MailMessage object. I know it's the same thing but...you can give it a try. 2) Check the port number, because usually it's 25 but it can differ from one server to another 3) Try configuring an email client like Outlook and if that doesn't also work....it's from somewhere else than your App Hope it helps.

        Do your best to be the best

        A Offline
        A Offline
        A M SOMAN
        wrote on last edited by
        #3

        Thanks for your suggessions karkster. Unfortunately it's not working. I came to know that the code is not working because my local machine does not have SMTP server installed on it. So I need to run the code on a machine where it is installed already. Will try for this.

        A 1 Reply Last reply
        0
        • A A M SOMAN

          Thanks for your suggessions karkster. Unfortunately it's not working. I came to know that the code is not working because my local machine does not have SMTP server installed on it. So I need to run the code on a machine where it is installed already. Will try for this.

          A Offline
          A Offline
          Andrei Ungureanu
          wrote on last edited by
          #4

          You only need IIS, which comes with Windows

          Do your best to be the best

          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