Gmail: How to send an email programmatically

后端 未结 6 2026
孤街浪徒
孤街浪徒 2020-12-08 18:13

Possible Exact Duplicate: Sending Email in C#.NET Through Gmail

Hi,

I\'m trying to send an email using gmail:

I tried various examples that I found on

6条回答
  •  一生所求
    2020-12-08 18:29

    I'm using the following code:

    SmtpClient sc = new SmtpClient("smtp.gmail.com");
    NetworkCredential nc = new NetworkCredential("username", "password");//username doesn't include @gmail.com
    sc.UseDefaultCredentials = false;
    sc.Credentials = nc;
    sc.EnableSsl = true;
    sc.Port = 587;
    try {
        sc.Send(mm);
    } catch (Exception ex) {
        EventLog.WriteEntry("Error Sending", EventLogEntryType.Error);
    }
    

提交回复
热议问题