【问题标题】:C# - Sending an Email from BlueHostC# - 从 BlueHost 发送电子邮件
【发布时间】:2012-05-07 19:30:02
【问题描述】:

我有 BlueHost,但我无法让它与 C# 一起使用。我已经从我登录的页面上删除了详细信息:

然后我使用此代码尝试发送电子邮件:

MailMessage message = new MailMessage
{
    From = new MailAddress("toEmail@site.com", "toEmail@site.com")
};
message.IsBodyHtml = false;
message.To.Add("email@site.com");
message.Subject = "my subject";
message.Body = "body";
message.Priority = MailPriority.Normal;
SmtpClient client = new SmtpClient
{
    Port = 465,
    Host = "box263.bluehost.com",
    EnableSsl = true,
    Credentials = new NetworkCredential("myEmail@site.com", "myPassword"),
    Timeout = 10000,
    UseDefaultCredentials = false
};
client.Send(message);

即使它有足够的时间(10 秒),它也会抛出一个错误说它超时。即使我不设置超时时间,它也只是坐一会儿。我也尝试过不使用 SSL,禁用“EnableSsl”,将端口更改为“26”,并将主机更改为“mail.embirk.com”,但这也不起作用。此外,这确实适用于 Microsoft Outlook 等第 3 方软件。有任何想法吗?谢谢。

编辑: 我还联系了 Bluehost 的二级支持技术人员,他们说他们也被难住了。他们说他们用 Thunderbird 试过了,一切都奏效了。他们说它可能正在寻找证书?

编辑 2:

这个 Outlook 注册表有帮助吗? (如果运行,这适用于 Outlook)。

REGEDIT4

[HKEY_CURRENT_USER\Software\Microsoft\Office\Outlook\OMI Account Manager\Accounts\steve@embirk.com]
"DCEmail"=dword:00000002
"IMAP Server"="box263.bluehost.com"
"IMAP Port"=dword:000003e1
"SMTP Server"="box263.bluehost.com"
"SMTP Port"=dword:000001d1
"Connection Type"=dword:00000003
"IMAP User Name"="steve@embirk.com"
"SMTP Display Name"="steve@embirk.com"
"SMTP Email Address"="steve@embirk.com"
"SMTP Reply To Email Address"="steve@embirk.com"
"SMTP Organization Name"=""
"Account Name"="steve@embirk.com"
"IMAP Timeout"=dword:0000003c
"SMTP Timeout"=dword:0000003c
"IMAP Secure Connection"=dword:00000001
"IMAP Skip Account"=dword:00000000
"IMAP Prompt for Password"=dword:00000001
"SMTP User Name"="steve@embirk.com"
"SMTP Use Sicily"=dword:00000002
"SMTP Secure Connection"=dword:00000001
"SMTP Split Messages"=dword:00000000
"SMTP Prompt for Password"=dword:00000000
"IMAP Root Folder"=""
"IMAP Polling"=dword:00000001
"IMAP Poll All Folders"=dword:00000001
"IMAP Dirty"=dword:00000000

【问题讨论】:

  • 不要误会,但您是否尝试过联系 bluehost 的客户支持?
  • 是的,我联系了 Bluehost 的二级支持技术人员,他们说他们也很困惑。他们说他们用 Thunderbird 试过了,一切都奏效了。他们说它可能在找证书?
  • 来自 BH 的引述:Bluehost 确实提供了一个免费的共享 SSL 证书,可供位于共享 IP 地址上的所有帐户使用。有关共享 SSL 证书的更多信息 -> my.bluehost.com/cgi/help/473
  • 你搞定了吗?我也有问题。
  • 我今天遇到了同样的问题,端口 465 上的 SMTP 在 Python 中完美运行,但在 C# 中超时。我的解决方法是使用端口587 并使用“boxXXX.bluehost.com”作为主机而不是“mail.mydomain.com”,就像 OP 在他的问题中所做的那样。

标签: c# email smtp bluehost


【解决方案1】:

我会尝试在客户端块之外声明凭据并将其分配给客户端凭据。

实际上完全摆脱了障碍。

NetworkCredential myCred = new NetworkCredential("xxxxxxxx", "xxxxxxxx");


client.Credentials = myCred;
client.port = 465,
client.Host = "box263.bluehost.com",
client.EnableSsl = true,
client.Credentials = new NetworkCredential("myEmail@site.com", "myPassword"),
client.Timeout = 10000,
client.UseDefaultCredentials = false

【讨论】:

  • 这没什么意义,因为您先设置凭据,然后再设置它们...
  • 因此 NetworkCredential 是 system.net 的一部分,而 client.Credentials 是 System.Net.Mail 的一部分。两个独立的对象。您正在实例化 NetworkCredential,然后将其分配给消息。这与设置两次凭据不同。
  • 设置“UseDefaultCredentials”的那一刻,它会清除“Credentials”属性中的任何值。因此,您应该在设置此属性后设置凭据
猜你喜欢
  • 1970-01-01
  • 2020-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-23
  • 2011-03-26
  • 2016-04-17
  • 2012-07-27
相关资源
最近更新 更多