使用 .NET 发送电子邮件 - 没那么容易

发布于 2024-08-03 19:54:38 字数 1318 浏览 4 评论 0原文

大约一年来,我在尝试使用 Visual C# 以编程方式发送和接收电子邮件时遇到了问题。我在网上找到的数百个示例中没有一个有效。不,我不只是复制和粘贴。我研究代码,并根据需要修改/添加/删除。

有人可以帮我解决这个问题吗?我正在尝试完成去年开始制作的一个简单的程序,但事实证明我几乎不可能弄清楚。

老实说,我不知道该怎么办了。该文档没有为我提供任何有用的信息,因为它们都没有起作用。我已将示例代码提供给其他人使用,它对他们有用 - 但对我不起作用!这是如何运作的?

我不知道发送邮件是否取决于我的计算机有哪些安全/防火墙设置。但为了以防万一,我甚至暂时完全关闭了所有安全和防火墙设置,只是为了看看它是否会发送电子邮件。

我不再有它的代码,因为我刚刚开始尝试再次做这件事,如果有人可以帮助我完成这项工作,我将非常感激。

所以,我想做的就是:

创建一个带有 2 个按钮和一个文本框的简单表单。 (当然,完成了) button1 检查电子邮件(但仅在消息框中显示主题和发件人,不下载消息) button2 将 textBox1 的内容发送到“[email] protected]

我的服务器设置是:

Username    [email protected]
Password    ***********
IMAP/POP Server (Incoming):     mail.bluebottle.com
SMTP Server     (Outgoing):     mail.bluebottle.com

SMTP should be port 25, 26 or 587
POP3 should be port 110, using SSL 995
IMAP should be port 143, using SSL 993


Thanks for taking the time to read. If I haven't explained anything clearly please say so and I will try to make more sense out of it for you.

For about a year now, I've had problems trying to send and receive email programmatically using Visual C#. Not a single example out of hundreds that I've found on the web have ever worked. And no, I don't just copy and paste. I study the code, and modify/add/remove as needed.

Can somebody PLEASE help me sort this out. I'm trying to finish what should've been a simple program that I started making last year, and it's proving to be almost impossible for me to figure out.

I honestly don't know what the heck to do anymore. The documentation provides no useful information to me because none of it has ever worked. I've given sample code to others to use, and it works for them - but not me! How does that work?

I don't know if SENDING mail is dependent upon what security/firewall settings my computer has or not. But just in-case, I have gone so far as to completely turn off all security and firewall settings temporarily just to see if it would send an email.

I don't have code for it anymore since I have only just started trying to do this thing again and I would really appreciate it if somebody could assist me in getting this working.

So, all I am trying to do is:

Create a simple Form with 2 buttons and a textbox. (done, ofcourse)
button1 checks for email (but only displays the subject and sender in a messagebox, does not download the message)
button2 sends the contents of textBox1 to "[email protected]"

My server settings are:

Username    [email protected]
Password    ***********
IMAP/POP Server (Incoming):     mail.bluebottle.com
SMTP Server     (Outgoing):     mail.bluebottle.com

SMTP should be port 25, 26 or 587
POP3 should be port 110, using SSL 995
IMAP should be port 143, using SSL 993


Thanks for taking the time to read. If I haven't explained anything clearly please say so and I will try to make more sense out of it for you.

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

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

发布评论

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

评论(2

断肠人 2024-08-10 19:54:38

没关系。我只是自己想出来的。就这么简单,123!或者是ABC?我忘记事情进展如何了。无论如何,如果有人感兴趣或需要知道如何用 C# 发送电子邮件,这对我有用:


string Sender     = "[email protected]";

string Username   = "username";
string Password   = "********";

string Recipient  = "[email protected]";

string Subject    = "Enter subject here.";
string Message    = "Enter message here.";

string Host       = "mail.server.com";
int Port          = 26;

using(MailMessage Mail = 
      new MailMessage(
      Sender,
      Recipient))
using (SmtpClient SmtpMail =
       new SmtpClient(
       Host,
       Port))
{
  Mail.Subject = Subject;
  Mail.Body    = Message;

  SmtpMail.EnableSsl = true;

  SmtpMail.Credentials =
        new System.Net.NetworkCredential(
        Username,
        Password);

  SmtpMail.Send(Mail);
}


Please note that the following using directive needs to be declared at the top of the document:

using System.Net.Mail;

编辑:使用模式 docos: http://msdn.microsoft .com/en-us/library/yh598w02(VS.71).aspx

Never mind. I just figured it out for myself. It's a simple as 123! or is it ABC? I forget how it goes. Any how, incase anybody's interested or needs to know how to send e-mail in C#, this is what worked for ME:


string Sender     = "[email protected]";

string Username   = "username";
string Password   = "********";

string Recipient  = "[email protected]";

string Subject    = "Enter subject here.";
string Message    = "Enter message here.";

string Host       = "mail.server.com";
int Port          = 26;

using(MailMessage Mail = 
      new MailMessage(
      Sender,
      Recipient))
using (SmtpClient SmtpMail =
       new SmtpClient(
       Host,
       Port))
{
  Mail.Subject = Subject;
  Mail.Body    = Message;

  SmtpMail.EnableSsl = true;

  SmtpMail.Credentials =
        new System.Net.NetworkCredential(
        Username,
        Password);

  SmtpMail.Send(Mail);
}


Please note that the following using directive needs to be declared at the top of the document:

using System.Net.Mail;

Edit: Using Pattern docos: http://msdn.microsoft.com/en-us/library/yh598w02(VS.71).aspx

眼波传意 2024-08-10 19:54:38

自今年以来,微软向所有 Hotmail 用户提供了 pop3 和 SMTP 支持。

  • POP3 服务器:pop3.live.com(端口 995)
  • SMTP 服务器:smtp.live.com(端口 25)
    {注:如果25端口已被封锁
    您的网络或 ISP,您可以
    使用 TLS 或 SSL 将 SMTP 端口设置为 587
    加密取决于客户端
    使用}

更多信息:
http://windowslivehelp.com/solutions/settings/archive/2009/01/06/send-and-receive-windows-live-hotmail-emails-from-a-mail-client.aspx< /a>

Since this year Microsoft made pop3 and SMTP support available to all Hotmail users.

  • POP3 Server: pop3.live.com (port 995)
  • SMTP Server: smtp.live.com (port 25)
    {Note: If port 25 has been blocked in
    your network or by your ISP, you can
    set SMTP port to 587 with TLS or SSL
    Encryption depending on the client in
    use}

More info:
http://windowslivehelp.com/solutions/settings/archive/2009/01/06/send-and-receive-windows-live-hotmail-emails-from-a-mail-client.aspx

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