2017-02-09 62 views
-1

我有一個巫婆文件,其中包含HTML,Javascript和Visual Basic,它實際上是一個網站(當啓動並運行時)。在ASP.NET應用程序中自動發送電子郵件的VB代碼

在點擊事件中,我能夠達到VB函數(測試),但現在是電子郵件部分。

Dim SmtpServer As New SmtpClient() 

SmtpServer.UseDefaultCredentials = true 
SmtpServer.Port = 25 
SmtpServer.Host = "12345.com" 

Dim mail As New MailMessage() 
mail.From = "[email protected]" 
mail.To.Add("[email protected]") 
mail.Subject = "Email Sending" 
mail.Body = "Testing the 1 and 2" 
SmtpServer.Send(mail) 

我想它會通過自身工作,但沒有,肯定有一些爲了使這項工作,配置了。它會在Dim SmtpServer As New SmtpClient()引發服務器錯誤所以我想我必須包括一些東西?

的錯誤是:

500 - 內部服務器錯誤。 您正在查找的資源存在問題,並且無法顯示。

+1

什麼是服務器錯誤? –

+0

你有一些對一個名爲'Smtp_Server'的變量的引用,其中的定義在哪裏?您還引用了一個名爲'e_mail'的變量,其中定義了哪個變量?調試時發生的實際錯誤是什麼? – David

+0

對不起大衛,修正了這個問題,讓人困惑的是,這裏是錯誤 –

回答

1

的問題是在這裏(從屬性不是字符串):

mail.From = "[email protected]" 

我用這個和工作:

mail.From = new System.Net.Mail.MailAddress(emailAddress, name);// Email-ID of Sender 

如果你不喜歡的發送者就可以做到這一點的用名:

mail.From = new System.Net.Mail.MailAddress(emailAddress); 
0

試試這個:

Try 
    Dim SmtpServer As New System.Net.Mail.SmtpClient() 

    SmtpServer.UseDefaultCredentials = true 
    SmtpServer.Port = 25 
    SmtpServer.Host = "csnavigateurs-qc-ca.mail.protection.outlook.com" 

    Dim mail As New MailMessage() 
    mail.From = "[email protected]" 
    mail.To.Add("[email protected]") 
    mail.Subject = "Email Sending" 
    mail.Body = "Testing the 1 and 2" 
    SmtpServer.Send(mail) 
    Response.Write("Success") 
Catch ex As Exception 
    Response.Write(ex.Message) 
End Try 

如果失敗的話這應該給你一個更清楚的錯誤消息。

+0

它可能需要一個包含某處 –