C# ~ Send mail example

感謝張睪大大提供code @0@

--------------------------------------------------------------------------------------------

using System.Net.Mail;
using System.Net;


private const string MailHost = "mail.ggyy.com";
private const string MailAccount = "ggyy@ggyy.com";
private const string MailPassword = "ggyy0204";


try
{
SmtpClient smtp = new SmtpClient();
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
smtp.Host = (MailHost);
smtp.Credentials = new NetworkCredential(MailAccount, MailPassword);
msg.From = new MailAddress("xdxd@xdxdxdxdxd.com", "GGYY Notify");
msg.IsBodyHtml = true;
msg.Subject = "GGYY Notify";
msg.Body = string.Format("Hi, this is a test, lol");
msg.To.Add(new MailAddress(Email));
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(msg);
msg.Dispose();

}
catch (Exception ex)
{

}

沒有留言:

發佈留言