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

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.