当我在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)