消息发送失败 [英] Messagge Sending Fail
本文介绍了消息发送失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从asp .net发送邮件.
以下是代码.
Hi,
I am trying to send mail from asp .net.
following is the code.
Imports System.Net
Imports System.Net.Mail
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub btnSend_Click(sender As Object, e As System.EventArgs) Handles btnSend.Click
Dim msgEmail As New MailMessage()
Dim smtpEmail As New SmtpClient()
Dim address As New MailAddress(TextBox1.Text.ToString)
Try
''Adding to address
If Not String.IsNullOrEmpty(TextBox1.Text.ToString) Then
msgEmail.[To].Add("target Mail id")
msgEmail.From = address
''Adding subject
msgEmail.Subject = "test"
''Adding body
msgEmail.Body = "This is a test mail"
''Creating object of SMTP class
smtpEmail.Host = "smtp.gmail.com"
smtpEmail.Port = 587
smtpEmail.EnableSsl = True
smtpEmail.UseDefaultCredentials = True
smtpEmail.Credentials = New NetworkCredential(TextBox1.Text.ToString, TextBox2.Text.ToString)
''Sending message
smtpEmail.Send(msgEmail)
Response.Write("<script>alert(''Message sent successfully.'');</script>")
Else
Response.Write("<script>alert(''Enter To address.'');</script>")
End If
Catch ex As Exception
Response.Write("<script>alert(''" + ex.Message + "'');</script>")
Finally
msgEmail.Dispose()
End Try
End Sub
End Class
在Textbox1和Textbox2中,我分别提供了用户名和密码.
但是,当我单击发送"按钮时,发送邮件失败"会发生异常
有人可以帮我解决这个问题吗?
预先感谢.
In Textbox1 and Textbox2, i am providing my username and password respectively.
But when i click on ''Send'' button then Exception occurs as "Failure Sending Mail"
Can anybody please help me to solve this problem?
Thanks in advance.
推荐答案
Imports System.Net
Imports System.Web.Mail
.........
Dim mail As New MailMessage()
mail.From = "From Address"
mail.To = "To Address"
mail.Cc = "CC Address"
mail.Bcc = "BCC Address"
mail.Subject = "Test Subject"
mail.Body = "Test Email Body"
mail.BodyFormat = MailFormat.Html
mail.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "UserName"
mail.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password"
SmtpMail.SmtpServer = "Smtp server"
If mail.Body.Trim <> "" Then
SmtpMail.Send(mail)
End If
设置所有电子邮件地址和凭据.
试试这个,然后回复我..它是否有效..?
Set all email address and credential.
Try this one and reply me.. it''s working or not..?
您好,Abhijit,
请尝试使用"smtpEmail.Port = 25".
谢谢,
Vipul
Hi Abhijit,
Please try " smtpEmail.Port = 25" this.
Thanks,
Vipul
这篇关于消息发送失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文