简体   繁体   English

如何在C#中从Windows应用程序发送电子邮件?

[英]How to send Email from windows application in c#?

I am working MS C# 2008. I created Windows form application. 我正在使用MS C#2008。我创建了Windows窗体应用程序。 And I need to send email from my application. 而且我需要从我的应用程序发送电子邮件。 so how do I configure smtp settings? 那么如何配置smtp设置?

EDIT 编辑

I got The following Exception 我收到以下异常

The SMTP server requires a secure connection or the client was not authenticated. SMTP服务器需要安全连接,或者客户端未通过身份验证。 The server response was: 5.5.1 Authentication Required. 服务器响应为:5.5.1需要身份验证。 Learn more at 了解更多

on smtp.send(message); 在smtp.send(message);上

I have not installed IIS so is it required for desktop app? 我尚未安装IIS,因此桌面应用程序需要它吗?

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中添加SMTP设置http://www.mitchelsellers.com/blogs/articletype/articleview/articleid/8/net-20-smtp-settings.aspx

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 );

why are a lot of you that are making the "IIS" suggestions using this as the backbone to solve the problem? 为何很多人都以此为基础提出“ IIS”建议来解决问题? 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,只需使用您应用程序的邮件功能???

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 -抢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM