Skip to main content
 首页 » 编程设计

C#之从 BlueHost 发送电子邮件

2024年01月02日44tintown

我有 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 等第三方软件。有任何想法吗?谢谢。

编辑: 我还联系了 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 

请您参考如下方法:

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

实际上完全摆脱了障碍。

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