在 .NET 程序中发送电子邮件时出错

发布于 2024-10-09 01:25:23 字数 876 浏览 0 评论 0原文

好的,我正在用 C# 编写一段代码,向某人发送电子邮件消息,代码如下:

MailAddress EmailFrom = new MailAddress("[email protected]");
MailAddress EmailTo = new MailAddress(txtTo);
MailMessage Email = new MailMessage(EmailFrom, EmailTo);
Email.Subject = txtTitle;
Email.Body = txtContext;
SmtpClient Client = new SmtpClient("www.gmail.com/");
Client.Send(Email);

我的主要问题是我收到一条错误消息:

SocketException:没有这样的主机已知 System.Net.Dns.GetHostByName (System.String 主机名) System.Net.Sockets.TcpClient.Connect (System.String 主机名,Int32 端口) System.Net.Sockets.TcpClient..ctor (System.String 主机名,Int32 端口)

并表示问题出在

Client.Send(Email);

所以,请有人帮助我解决这个问题。

Ok so I am doing a code in C# to send to a persons email a message, here is the code:

MailAddress EmailFrom = new MailAddress("[email protected]");
MailAddress EmailTo = new MailAddress(txtTo);
MailMessage Email = new MailMessage(EmailFrom, EmailTo);
Email.Subject = txtTitle;
Email.Body = txtContext;
SmtpClient Client = new SmtpClient("www.gmail.com/");
Client.Send(Email);

My principal problem is that I get an error that says:

SocketException: No such host is known System.Net.Dns.GetHostByName (System.String
hostName)
System.Net.Sockets.TcpClient.Connect
(System.String hostname, Int32 port)
System.Net.Sockets.TcpClient..ctor
(System.String hostname, Int32 port)

And says that the problem is on

Client.Send(Email);

So, could please some one help me with this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

地狱即天堂 2024-10-16 01:25:23

“www.gmail.com/” 不是有效的主机名(末尾有斜杠)。它实际上可能(也)不是 GMail 的 SMTP 主机。

"www.gmail.com/" is not a valid host name (it has a slash at the end). It might (also) not actually be GMail's SMTP host.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文