2017-02-09 63 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

它可能需要一个包含某处 –