Problem while sending mail

Posted by Emil under ASP.NET on 3/2/2012 | Points: 10 | Views : 1332 | Status : [Member] | Replies : 3
I have written the code for mail sending
public void SendMail()
{
try
{
MailMessage message = new MailMessage();
message.From = new MailAddress(ConfigurationManager.AppSettings["FromAddress"]);
message.To.Add(ConfigurationManager.AppSettings["ToAddress"]);
message.Subject = "Test Mail";
message.Body = "BX-Test Mail";
SmtpClient client = new SmtpClient(ConfigurationManager.AppSettings["SMTPServer"], Convert.ToInt32(ConfigurationManager.AppSettings["SMTPPort"]));
NetworkCredential credential = new NetworkCredential(ConfigurationManager.AppSettings["UserName"], ConfigurationManager.AppSettings["Password"]);
client.UseDefaultCredentials = false;
client.Credentials = credential;
client.Send(message);
}
catch
{
throw;
}

When i deployed in server i am getting the error

Value cannot be null.
Parameter name: address


}





Responses

Posted by: Hmanjarawala on: 3/2/2012 [Member] Bronze | Points: 25

Up
0
Down
At a first glance i feel that your FromAddress key may be not present or spelled incorrectly in your config file.
kindly check it for other keys also.

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Emil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Blessyjees on: 3/2/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi

I feel that this error is not occurred from sendmail function. Please check where you are using the variable "address" as parameter and give a value for this.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Emil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/2/2012 [Member] Silver | Points: 25

Up
0
Down

First pass a statict valule like "sanjaya@scalable-systems.com"
If it works then check the address value you set in web.config may have some error.

Thanks,
Sanjay

Emil, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response