gpt4 book ai didi

c# - 邮件发件人不工作

转载 作者:太空宇宙 更新时间:2023-11-03 15:57:38 25 4
gpt4 key购买 nike

我正在尝试通过 gmail 将自动生成的密码发送给用户,但它不起作用。我试过在许多论坛上搜索,这是我正在使用的代码。每个论坛上给出的几乎相同,仍然无法正常工作。

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Drawing;
using System.Net;
using System.Net.Mail;

/// <summary>
/// Summary description for GmailSender
/// </summary>
public class GmailSender
{
public GmailSender()
{
//
// TODO: Add constructor logic here
//
}
public static bool SendMail(string gMailAccount, string password, string to, string subject, string message)
{
try
{
NetworkCredential loginInfo = new NetworkCredential("mymail@gmail.com", "mypassword");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("mymail@gmail.com");
msg.To.Add(new MailAddress(to));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;

SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Send(msg);

return true;
}
catch (Exception)
{
return false;
}
}
}

谁能帮我解决这个问题?

最佳答案

试试这个(对于 gmail smtp 服务器)。

SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

关于c# - 邮件发件人不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22863522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com