/// <summary>
/// 用SMTP發送email
/// </summary>
/// <param name="to">收件者</param>
/// <param name="cc">cc</param>
/// <param name="attfile">附件檔案path</param>
/// <param name="subject">主題</param>
/// <param name="body">內文</param>
protected bool bspg_SendMail(string to, StringCollection cc, StringCollection attfile, string subject, string body)
{
bool rc = true;
try
{
MailAddress ma_From = new MailAddress("abc@hinet.net.net", "系統");
MailAddress ma_To = new MailAddress(to, to.Split('@')[0].ToString());
MailMessage message = new MailMessage(ma_From, ma_To);
MailAddressCollection mailcc = new MailAddressCollection();
if (cc.Count > 0) //CC
{
foreach (string txt in cc)
{
MailAddress scc = new MailAddress(txt, txt.Split('@')[0].ToString()); //不給DISPLAY NAME 經測試 CC 會收不到
message.CC.Add(scc);
}
}
if (attfile.Count > 0) //附件
{
foreach (string str in attfile)
{
if (File.Exists(str) == true)
message.Attachments.Add(new Attachment(str));
else
{
return false;
}
}
}
message.From = ma_From;
message.To.Add( ma_To);
message.Subject = subject;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Body = body;
message.IsBodyHtml = false;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.UseDefaultCredentials = false;
client.Host = "192.168.1.100";
client.Send(message);
}
catch (Exception )
{
rc = false;
}
return rc;
}