C# 傳送電子郵件原始碼片段

玉米幫發表於2018-12-12

下面程式碼內容是關於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());
}
}
}

相關文章