Error while using System.Net.Mail.SmtpClient to send mail
-
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
-
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 M SOMAN wrote:
Any suggessions?
- 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 M SOMAN wrote:
Any suggessions?
- 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
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.
-
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.
You only need IIS, which comes with Windows
Do your best to be the best