以下是使用.Net寄信的程式碼,以c#做範例
SmtpClient smtpObj =
new SmtpClient(
"example.com.tw");
//宣告物件,傳入參數是mail主機MailMessage msg =
new MailMessage();
MailAddress fromAddress =
new MailAddress(
"stbird@example.com.tw",
"stbird");
msg.From = fromAddress;
//設定寄件人msg.To(
new MailAddress(
"stbird@example.com.tw",
"stbird"));
//設定收件人string[] bccaddress =
new string[]{
"john@example.com.tw",
"mary@example.com.tw"};
for (
int i=0;i<bccaddress.Length;i++)
{
msg.Bcc.Add(bccaddress[i]);
}
//設定cc對象msg.Subject =
"信件標題";msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Body =
"<html><body></p>信件內容</p></body></html>";
try{
smtpObj.Send(msg);
//寄出}
catch(Exception ex)
{
}
msg.Dispose();