发送邮件时遇到问题。我的代码很简单,如下所示。 当此代码启动时,它会给出错误:
请求'System.Net.Mail.SmtpPermission类型的权限, 系统,版本= 2.0.0.0,文化=中立, PublicKeyToken = b77a5c561934e089'失败。
当我搜索此错误时,他们建议将web.config信任完整设置或端口从587更改为25和其他东西,但没有工作。还有什么呢?
Sub MailGonder()
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Host = "mail.excelinefendisi.com"
SmtpServer.Credentials = New Net.NetworkCredential("info@excelinefendisi.com", "mypassword")
SmtpServer.Port = 587
mail.From = New MailAddress("info@excelinefendisi.com")
mail.To.Add("volkan.yurtseven@hotmail.com")
mail.Subject = "Test Mail"
mail.Body = "This is for testing SMTP"
SmtpServer.EnableSsl = True
SmtpServer.Send(mail)
End Sub
答案 0 :(得分:0)
使用此代码,非常适合我:
Dim iphost As IPHostEntry = Dns.GetHostByName(Dns.GetHostName())
Dim Emailmessage As New MailMessage()
Emailmessage.From = New MailAddress("from_Email@hotmail.com")
Emailmessage.To.Add("To_Email@hotmail.com")
Emailmessage.Subject = "tTest Mail"
Emailmessage.Body = ("This is for testing SMTP")
Dim smtp As New SmtpClient("smtp.live.com")
smtp.Port = 587
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential("your_email@hotmail.com.com", "Password")
smtp.Send(Emailmessage)