C# 发送电子邮件源码片段

下面代码内容是关于C# 发送电子邮件片段的代码,应该对各位有所用途。

using System;
using System.Web;
using System.Web.Mail;
public class TestSendMail
{
public static void Main()
{
try
{
MailMessage message = new MailMessage();
message.From = from@domain.com;
message.To = pengyun@cobainsoft.com;
message.Cc = ;
message.Bcc = ;
message.Subject = Subject;
message.Body = Content of message;

message.Attachments.Add(new MailAttachment(c:\attach.txt, MailEncoding.Base64));

SmtpMail.Send(message);
System.Console.WriteLine(Message has been sent);
}
catch(Exception ex)
{
System.Console.WriteLine(ex.Message.ToString());
}
}
}





posted @ 2018-12-12 15:40  玉米帮  阅读(377)  评论(0编辑  收藏  举报