簡體   English   中英

從asp.net聯系人頁面發送電子郵件時出錯

[英]error when sending email from asp.net contact page

我試圖從我的聯系頁面發送電子郵件,但我不斷收到錯誤消息

我已經在下面粘貼了我的代碼以及出現的錯誤消息。

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    '

    Dim SendPw As New System.Net.Mail.MailMessage
    Dim Smtp As New System.Net.Mail.SmtpClient()


    SendPw.To.Add(email.Text)
    SendPw.From = New System.Net.Mail.MailAddress("shumbasoft@gmail.com")
    SendPw.Subject = "Password for you"
    SendPw.Priority = Net.Mail.MailPriority.High
    SendPw.Body = "This your new password: "
    SendPw.IsBodyHtml = False
    Smtp.Host = "smtp.gmail.com"
    Smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.PickupDirectoryFromIis
    Smtp.Send(SendPw)
End Sub

電子郵件發送錯誤

您配置了IIS嗎? 或嘗試使用此代碼,它將為我帶來良好的效果:

Dim msgMail As New MailMessage()
Dim myMessage As New MailMessage()
myMessage.From = New MailAddress("sender's email", "sender`s name and surname")
myMessage.[To].Add("recipient's email")
myMessage.Subject = "Subject"
myMessage.IsBodyHtml = True

myMessage.Body = "Message Body"


Dim mySmtpClient As New SmtpClient()
Dim myCredential As New System.Net.NetworkCredential("email", "password")
mySmtpClient.Host = "your smtp host address"
mySmtpClient.UseDefaultCredentials = False
mySmtpClient.Credentials = myCredential
mySmtpClient.ServicePoint.MaxIdleTime = 1

mySmtpClient.Send(myMessage)
myMessage.Dispose()

您需要導入Imports system.net.mail

這對我有用!! 從本地主機到gmail

 Dim Body As String = "From: " + fname.Text + " " + lname.Text + Environment.NewLine +              "Email:  " + email.Text + Environment.NewLine + Environment.NewLine + "Message" + Environment.NewLine + txtComment.Text


    Dim xx As New System.Net.Mail.SmtpClient
    xx.EnableSsl = True
    xx.Host = "smtp.gmail.com"
    Dim cred As New System.Net.NetworkCredential("example@gmail.com", "examplepassword")
    xx.Credentials = cred
    xx.Send(email.Text, "sendexample@gmail.com ", subject.Text, Body)
    ClearFields()
    lblEmail.ForeColor = Drawing.Color.Green
    lblEmail.Text = "message sent"
    lblEmail.Visible = True

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM