如何从 c# 中的 Windows 应用程序发送电子邮件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/780534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to send Email from windows application in c#?
提问by Vikas
I am working MS C# 2008. I created Windows form application. And I need to send email from my application. so how do I configure smtp settings?
我正在使用 MS C# 2008。我创建了 Windows 窗体应用程序。我需要从我的应用程序发送电子邮件。那么如何配置 smtp 设置呢?
EDIT
编辑
I got The following Exception
我得到以下异常
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。了解更多信息
on smtp.send(message);
在 smtp.send(message);
I have not installed IIS so is it required for desktop app?
我还没有安装 IIS,那么桌面应用程序需要它吗?
回答by rid00z
You can add the SMTP settings within the App.Config http://www.mitchelsellers.com/blogs/articletype/articleview/articleid/8/net-20-smtp-settings.aspx
您可以在 App.Config http://www.mitchelsellers.com/blogs/articletype/articleview/articleid/8/net-20-smtp-settings.aspx 中添加 SMTP 设置
And then use System.Net.Mail.SmtpClient and System.Net.Mail.MailMessage to send and create the emails.
然后使用 System.Net.Mail.SmtpClient 和 System.Net.Mail.MailMessage 发送和创建电子邮件。
c = new System.Net.Mail.SmtpClient();
msg = new System.Net.Mail.MailMessage();
System.Net.Mail.MailAddress a = new System.Net.Mail.MailAddress( sEmailAddress, sWho );
msg.To.Add( a );
msg.From = new System.Net.Mail.MailAddress("");
msg.ReplyTo = new System.Net.Mail.MailAddress("");
msg.Subject = "Web Inquiry";
msg.Body = msgBody.ToString();
c.Send( msg );
回答by rid00z
why are a lot of you that are making the "IIS" suggestions using this as the backbone to solve the problem? What if this is a deployed application? you going to have the client install and run IIS on their mediocre system just use the mail functionality of your app???
为什么你们中的很多人都使用它作为解决问题的主干来提出“IIS”建议?如果这是一个已部署的应用程序怎么办?你打算让客户端在他们普通的系统上安装和运行 IIS 只是使用你的应用程序的邮件功能???
That doesn't make sense to me.
这对我来说没有意义。
Those of you looking for a solution on sending emails thru win apps, do a google search on "using gmail to send email in c#".
那些正在寻找通过 win 应用程序发送电子邮件的解决方案的人,请在 Google 上搜索“使用 gmail 在 c# 中发送电子邮件”。
-Rob
-抢