求 在asp.net程序中发邮件的代码

[复制链接]
查看11 | 回复0 | 2009-6-13 10:56:55 | 显示全部楼层 |阅读模式
引用命名空间:using System.Net.Mail;public class WebSendMail
{
///
/// 发送电子邮件
///
/// 邮件主题
/// 邮件内容
/// 发件主机服务器
/// 接收邮箱
/// 发件邮箱
/// 发件邮箱密码
/// 邮件发送情况
/// 邮件附件路径,无附件传""值
///
public static bool SendMail(string MailTitle, string MailContent, string MailServer, string EMail,
string SendEMail, string SendMailPwd, out string Msg, string FilePath)
{
Msg = "代码未执行!";
bool IsFinish = false;
try
{
SmtpClient client = new SmtpClient(MailServer);
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential(SendEMail, SendMailPwd);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage message = new MailMessage(SendEMail, EMail);
message.Subject = MailTitle;
message.Body = MailContent;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
if (FilePath != "")
{
Attachment data = new Attachment(FilePath, System.Net.Mime.MediaTypeNames.Application.Octet);
message.Attachments.Add(data);
}
try
{
client.Send(message);
IsFinish = true;
Msg = "邮件发送成功!";
}
catch
{
IsFinish = false;
Msg = "邮箱不可用!";
}
}
catch (Exception ex)
{
IsFinish = false;
Msg = "错误:" + ex.Message;
}
return IsFinish;
}
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行