在Windows窗体中使用网络凭据将邮件发送为true

我想在C#Windows应用程序中创建一个用于发送电子邮件的应用程序。我使用了smtp服务器,但是我不想设置网络凭据。所以我将其设置为true。但是出现错误。


SMTP服务器需要安全连接,或者客户端未通过身份验证。服务器响应为:5.5.1需要身份验证。了解更多


这是代码:


SmtpClient oClient = new SmtpClient();

oClient.Host = "smtp.gmail.com";

oClient.Port = 25;

oClient.UseDefaultCredentials = true;

oClient.Credentials = new System.Net.NetworkCredential();

oClient.EnableSsl = true;

MailMessage oMail = new MailMessage();

oMail.To.Add(txtTo.Text.Trim());

oMail.From = new MailAddress("testmail@gmail.com");

oMail.Subject = txtSubject.Text;

oMail.Body = txtBody.Text;

oMail.IsBodyHtml = true;

oClient.Send(oMail);

MessageBox.Show("Mail Send");

在这里,我将主机设置为gmail.com,我需要使用所有电子邮件服务提供商发送和接收邮件。那么如何设置主机和端口?


三国纷争
浏览 592回答 2
2回答
打开App,查看更多内容
随时随地看视频慕课网APP