我正在尝试从网页发送电子邮件。 我的在线网络服务器只允许我使用自己的电子邮件服务器。
以下是来自内部try..catch的错误代码:
Insufficient permissions for setting the configuration property 'port'. (E:\kunden\homepages\36\d457818200\www\zSession\web.config line 48)
这是我的web.config:
web.config
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="name@email.com">
<network enableSsl="false" host="smtp.email.com"
userName="name@email.com"
password="pass1" port="587" defaultCredentials="false" clientDomain="domainname" />
</smtp>
</mailSettings>
</system.net>
我的网络服务器电子邮件的端口在587是正确的。 这是我的电子邮件帐户的SSL设置。 我选择SSL是真的,因为此电子邮件服务器上有加密级别。
错误代码存在于vb代码的正文中:
Dim message As New MailMessage()
Dim fromAdd As MailAddress = New MailAddress("name@email.com")
With message
.[To].Add("name1@email1.com")
.Subject = "Choose Session Members"
.From = fromAdd
.IsBodyHtml = True
.Priority = MailPriority.Normal
.BodyEncoding = Encoding.Default
.Body = "body"
End With
Dim host = Request.Url.Host
Dim smtpClient As New SmtpClient()
With smtpClient
.Host = "smtp.email.com"
.Port = 587
.EnableSsl = True
.UseDefaultCredentials = True
.Credentials = New NetworkCredential("name@email.com", "pass1")
.DeliveryMethod = SmtpDeliveryMethod.Network
.Send(message)
.Dispose()
End With
答案 0 :(得分:0)
我希望这会有所帮助。
'Name Space
Imports System.Object
Imports System.Net.Mail.SmtpClient
Imports System.Net.Mail
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("xx@xx")
mail.[To].Add("xx@xx")
'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"
'set the server
Dim smtp As New SmtpClient("localhost")
'send the message
Try
smtp.Send(mail)
Response.Write("Your Email has been sent sucessfully - Thank You")
Catch exc As Exception
Response.Write("Send failure: " & exc.ToString())
End Try
来源: - vb.net send email
答案 1 :(得分:0)
我认为这是关于它的
var message = new MailMessage();
message.To.Add("name1@email1.com");
message.From = new MailAddress("name@email.com");
message.Subject = "Choose Session Members";
message.Body = "body";
message.IsBodyHtml = True
message.BodyEncoding = Encoding.Default
var client = new SmtpClient("smtp.email.com", 587);
client.UseDefaultCredentials = False
client.Credentials = new System.Net.NetworkCredential("name@email.com", "pass1");
client.EnableSsl = True
client.DeliveryMethod = SmtpDeliveryMethod.Network
client.Send(message);
答案 2 :(得分:0)
我认为您的凭据之间存在冲突。
我试着改变这个:
.UseDefaultCredentials = True
.Credentials = New NetworkCredential("name@email.com", "pass1")
对此:
.UseDefaultCredentials = False
.Credentials = New NetworkCredential("name@email.com", "pass1")
某些SMTP服务器要求在服务器代表客户端发送电子邮件之前对客户端进行身份验证。如果服务器请求此SmtpClient对象应使用当前登录用户的默认凭据进行身份验证,请将此属性设置为true。对于客户端应用程序,这是大多数情况下的期望行为。 还可以使用应用程序和计算机配置文件指定凭据信息。有关更多信息,请参阅元素(网络设置)。 如果UseDefaultCredentials属性设置为false,则在连接到服务器时,Credentials属性中设置的值将用于凭据。如果UseDefaultCredentials属性设置为false并且尚未设置Credentials属性,则会以匿名方式将邮件发送到服务器。