C#如何发送电子邮件? [英] C# how to send email?

查看:487
本文介绍了C#如何发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#.net 4.0,并想发送电子邮件与主题和正文的地址,身体会包含在我的应用程序从几文本框的一些信息。

I am using C#.NET 4.0 and would like to send an email to an address with a subject and a body, the body will contain some information from a few text-boxes in my application.

我没有什么在C#中发送电子邮件没有经验,所以这里的任何帮助将是AP preciated。我所知道的是,你必须使用System.Net.Mail命名空间。我想这code,但它给了一个失败发送邮件的异常。

I have little to no experience with sending emails in C#, so any help here would be appreciated. All I know is that you have to use the System.Net.Mail namespace. I tried this code but it gave an "Failure sending Mail" exception.

        new SmtpClient("smtp.server.com", 25).Send("test@hotmail.com",
                                       "test@gmail.com",
                                       "subject",
                                       "body");

什么是错的上述code?此外,有没有更好的方法来发送电子邮件?

What is wrong with the above code? Furthermore, is there any better way to send the email?

推荐答案

我曾与三个著名的ISP的主机我的客户的网站。所有这三个ISP的指示,我用localhost作为SMTP服务器名称。

I have worked with three well known ISP’s to host my client’s websites. All three ISP's instructed me to use "localhost" as the smtp server name.

这篇关于C#如何发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆