Hi ,

Am developing a Windows application in which one module has to send a report to customers a mail.. the Question is

I use net.mail namespace in c# and here comes the code .

try
{
SmtpClient smtp = new SmtpClient();
MailMessage msg = new MailMessage();
                
smtp.Credentials = new System.Net.NetworkCredential("myusername", "password");
smtp.Port = 587;
//smtp.Port = 465;
smtp.Host = "smtp.gmail.com";
msg = new MailMessage();
msg.From = new MailAddress("fromtxtBox.text");
msg.To.Add("totxtBox.text");
msg.Subject = subtxtBox.text;
msg.Body = drafttxtBox.text
smtp.Send(msg);
label1.Text = "mail sent";
               
}
catch (Exception ec)
{

   MessageBox.Show(ec.Message);
}

It works good in my previous task bt thn now i always get exception....why is that so....

Recommended Answers

Please, if you get an error post it up...

Jump to Post

Are you having a problem with the code? Any errors at all?

Jump to Post

All 7 Replies

Please, if you get an error post it up...

Are you having a problem with the code? Any errors at all?

hi,

It gives an exception as mail sending failed....

Cool. We need to know what the exception is. Thanks.

Yes post your errors,then we can help..

@ pro_learner.. That's exactly what I said. Thanks for stressing a little more on the point. ROFL!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.