gpt4 book ai didi

c# - 如何使用 GMail 帐户发送电子邮件?

转载 作者:太空宇宙 更新时间:2023-11-03 16:01:27 24 4
gpt4 key购买 nike

<分区>

我使用以下代码从我的 Gmail 帐户发送电子邮件。但是出现以下错误。无法连接到远程服务器我的代码有什么问题?

        string from = "xxxx@gmail.com";
string to = TxtTo.Text;
string cc = "yyyy@gmail.com";
string subject = TxtSubject.Text;
string body = EdtContext.Content;
MailMessage EMail = new MailMessage();
MailAddress Sender = new MailAddress(from);
EMail.From = Sender;
EMail.To.Add(to);
EMail.CC.Add(cc);
EMail.Body = body;
EMail.IsBodyHtml = true;
EMail.Subject = subject;
EMail.BodyEncoding = Encoding.UTF8;
SmtpClient Local = new SmtpClient("smtp.gmail.com");//--- smtp
Local.Port = 465;
Local.EnableSsl = true;
Local.UseDefaultCredentials = false;
Local.Credentials = new System.Net.NetworkCredential("xxxx@gmail.com", "*****");//------ email user and pass in sobhan mail
Local.Send(EMail);

***************
**Port 587 solved problem**

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