傳送郵件

暖暖De幸福發表於2024-08-08

public void SendEmail()
{
    var path = Path.Combine(Server.MapPath("../"), "Content\\template\\email\\eCalendar.html");
    var template = System.IO.File.ReadAllText(path);

    var body = template.Replace("{{Name}}", "")
                        .Replace("{{Type}}", "")
                        .Replace("{{Description}}", "")
                        .Replace("{{Subject}}", "");

    string smtpServer = "Lamb.corning.com";
    int smtpPort = 25;
    SmtpClient smtp = new SmtpClient(smtpServer, smtpPort);
    Email.DefaultSender = new SmtpSender(smtp);
    var result = Email.From("MTE OA(DO NOT REPLY) <noreply@corning.com>")
                        .To("zhangs49@corning.com")
                        //.CC("zhangs49@corning.com")
                        .Subject("郵件主題")
                        .Body(body, true)
                        .Send();
}

相關文章