如何从C#Net应用程序发送电子邮件 [英] how send an email from c# net application
本文介绍了如何从C#Net应用程序发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用C#ms sql server 2005应用程序.
使用水晶报表进行应用.
我必须发送一份报告电子邮件,我将从应用程序将其另存为pdf文件.
所以请告诉我
1.如何发送电子邮件?
2.为此需要什么东西(例如导入什么东西)
提前感谢
问候
Nirmala Saravanan
i am using an C# ms sql server 2005 application.
Using crystal reports for the applciation.
I have to send a email of an Report which i will save as pdf file from the application.
So pls help me by telling me
1.How to send email?
2.What r the things needed for that (like what to import etc)
Thanx in advance
Regards
Nirmala Saravanan
推荐答案
您可以使用System.Net.Mail命名空间并创建新的MailMessage()和新的SmtpClient().然后只需在其上填写属性即可.
You can use the System.Net.Mail namespace and create a new MailMessage() and also a new SmtpClient(). Then just fill in the properties on them.
^ ]
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("userid@gmail.com");
mail.To.Add(clientmailaddress);
mail.Subject = "subject";
mail.Body = "body";
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("your attachment file");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("userid@gmail.com", "password");
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}
catch (Exception ex)
{
MessageBox.Show("mail sending fail");
}
我认为这可能对您有帮助...
I think this might help you...
这篇关于如何从C#Net应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文