我在我的程序中有一個函數,用於從Google帳戶發送電子郵件。發送郵件時發生錯誤system.web.httpexceptions:郵件無法發送到SMTP服務器
我寫了這段代碼後,它用於正常工作,它發送電子郵件就像它應該。然而,現在,我無法實現它的工作。 (我現在正在開發Windows 7 64位,如果這會有所作爲)。
錯誤我得到的(這是從代碼中的第一個錯誤消息)是:
system.web.httpexceptions:郵件無法發送到SMTP服務器 。傳輸錯誤代碼是0x80040217。服務器響應 不可用 - > system.reflection.targetinvocationexception: 異常已被調用的目標引發。 - > system.runtime.interopservice.comexception(0x80040211):郵件 無法發送到smtp服務器。運輸錯誤代碼是 0x80040217。服務器響應不可用。
這是代碼:
void sendEmail(string [] emailList, int emailLength, string fileName)
{
int i = 0; //variable to act as temporary index into emailList array
try
{
try
{
MailMessage message = new MailMessage();
//Because using google server, requires SSL
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate",1);
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","[email protected]");
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword","thepassword");
message.From = "[email protected]";
message.To = emailList[i];
//add Bcc
while (++i < emailLength)
{
message.Bcc = emailList[i];
}//end while
message.Subject = "Test Subject";
message.Body = "Test Body";
MailAttachment fileAttach = new MailAttachment(fileName);
message.Attachments.Add(fileAttach);
try
{
SmtpMail.SmtpServer = "smtp.gmail.com";
預先感謝您!
0x80040217訪問表示服務器拒絕您的要求。檢查此調試步驟:http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/2bdde9e6-b57a-4b12-b476-7bcf1f8f66d5/ – devshorts 2012-04-06 22:04:53
是的,你給我的鏈接幫助,感謝名單devshorts – 2012-04-06 22:11:30
發表您的解決方案,如果你發現它 – devshorts 2012-04-07 01:48:53