C# SMTP寄送郵件加上附件檔案
資料來源:http://blog.xuite.net/chu.hsing/Think/33046869
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Mail;//
namespace SendMailTest
{
class Program
{
static void Main(string[] args)
{
try
{
SmtpClient sc = new SmtpClient(“ms14.hinet.net”);//
sc.Port = 25;
MailAddress receiverAddress = new MailAddress(“[email protected]”, “潘建誌”);//
MailAddress senderAddress = new MailAddress(“[email protected]”, “精創”);
MailMessage mail = new MailMessage(senderAddress,receiverAddress);//
mail.Subject=”test”;
mail.Body = “yahoo”;
mail.IsBodyHtml = true;//
Attachment attachment = new Attachment(@”C:\Test\JackyTest.zip”);//
mail.Attachments.Add(attachment);//
sc.Send(mail);//
Console.WriteLine(“Done.”);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
}
}