System.Net.Mail作为localhost工作,但是当我将它添加到我的Web服务器时它没有

时间:2013-12-18 05:30:16

标签: asp.net system.net.mail

当我在VWD 2010中“调试”为localhost时,此程序有效。 当我将它插入我的网络服务器时,我的Try ... Catch会收到此错误:

Request for the permission of type 'System.Net.Mail.SmtpPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

这是我的代码:

Imports System.Net.Mail
Dim msg As New System.Net.Mail.MailMessage
Dim fromAdd As MailAddress = New MailAddress("nsamefrom@mail.com")
msg.[To].Add("nameto@email.com")
msg.Subject = "Email Works!!!!!!!!"
msg.From = fromAdd
msg.IsBodyHtml = True
msg.Priority = System.Net.Mail.MailPriority.Normal
msg.BodyEncoding = Encoding.Default
msg.Body = "<h1>Body!!!!!!</h1>"
Dim host = Request.Url.Host
Dim smtpClient As New SmtpClient("smtp.email.com", "587")
smtpClient.EnableSsl = True
smtpClient.UseDefaultCredentials = False
smtpClient.Credentials = New System.Net.NetworkCredential("user", "pass")
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network
smtpClient.Send(Message)    

1 个答案:

答案 0 :(得分:1)

将gmail smtp的端口号替换为25,

它也适用于托管服务器。

来源:http://forums.asp.net/t/1624378.aspx