1. 在HWIT以SmtpClient發送內部郵件OK,外送郵件需驗證
public static void SendMail(string 人, string 信)
{
//------- 認證
SmtpClient smtpClient = new SmtpClient();
MailAddress from = new MailAddress("csjou@mail.hwc.edu.tw");
smtpClient.Host = "mail.hwc.edu.tw";
//NetworkCredential basicCredential =
// new NetworkCredential("csjou", "xxxxxxxx");
//smtpClient.UseDefaultCredentials = false;
//smtpClient.Credentials = basicCredential;
// Set destinations for the e-mail message.
MailAddress to = new MailAddress(人);
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = 信;
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
//string 附檔 = @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg";
//Attachment 附件 = new Attachment(附檔);
//message.Attachments.Add(附件);
smtpClient.Send(message);
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
string answer = Console.ReadLine();
// If the user canceled the send, and mail hasn't been sent yet,
// then cancel the pending operation.
if (answer.StartsWith("c") && mailSent == false)
{
smtpClient.SendAsyncCancel();
}
// Clean up.
message.Dispose();
Console.WriteLine("Goodbye.");
}
2.
3. 解除紅字註解(加入個人帳號、密碼驗證),可以寄出外送郵件
沒有留言:
張貼留言