0

This program works when I "Debug" in VWD 2010 as localhost. When I insert it into my webserver my Try...Catch get this error:

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

Here is my code:

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)    
teledextri
  • 125
  • 1
  • 3
  • 14

1 Answers1

1

replace port no for gmail smpt by 25,

it will worke on hosting server too.

Source : http://forums.asp.net/t/1624378.aspx

Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115