C#如何发送电子邮件?发送电子邮件

2023-09-02 01:42:22 作者:習慣沉默

我使用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.