电子邮件。从数据库中解决 [英] Email. To address from database
问题描述
我有以下方法
I have below method
Private Sub SendHtmlFormattedEmail(ByVal recepientEmail As String, ByVal subject As String, ByVal body As String)
Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage
Try
mailMessage.From = New MailAddress(ConfigurationManager.AppSettings("UserName"))
' mailMessage.CC.Add("danish.habib@plan-international.org")
mailMessage.Bcc.Add("spober_woh@yahoo.com")
mailMessage.Subject = subject
mailMessage.Body = body
mailMessage.IsBodyHtml = True
mailMessage.To.Add(New MailAddress(recepientEmail))
Dim files As List(Of HttpPostedFile) = DirectCast(Cache(Me.Key), List(Of HttpPostedFile))
For Each file As HttpPostedFile In files
mailMessage.Attachments.Add(New Attachment(file.InputStream, Path.GetFileName(file.FileName), file.ContentType))
Next
mailMessage.From = New MailAddress("omer@planrbme.com.pk")
Dim smtp As New SmtpClient()
smtp.Host = "202.165.228.15"
smtp.EnableSsl = False
smtp.Credentials = New System.Net.NetworkCredential("omer@planrbme.com.pk", "Pakistan_123")
smtp.Port = 25
smtp.Send(mailMessage)
Catch ex As Exception
ex.Message.ToString()
End Try
End Sub
当我从下面的数据库中获取mail.To地址
mailMessage.To.Add(新邮件地址(recepientEmail))然后它没有向我的电子邮件地址发送任何电子邮件,它也没有给出任何例外,但当我硬编码时它就像
mailMessage。 To.Add(d.habib@plan-international.org)它发送电子邮件到那个地址为什么会这样?
我试过的:
我试图发送电子邮件到谷歌帐户,如marktabor@gmail.com它发送正确它没有发送只是与这个域和当我我正在使用该方法获得电子邮件地址,然后它正确地收到电子邮件,如d.habib@plan-international.org但它没有发送到该电子邮件,当我硬编码然后它发送电子邮件到该地址
When i am getting the mail.To address from the database like below
mailMessage.To.Add(New MailAddress(recepientEmail)) then it did not send any email to my email address it did not give any exception as well , but when i hard code it like
mailMessage.To.Add("d.habib@plan-international.org") it send email to that address why it is so?
What I have tried:
I have tried to send email to google account like marktabor@gmail.com it send correctly it did not send just with this domain and when i am using the method to get the email address then it gets the email correctly like d.habib@plan-international.org but it did not send to that email when i hard code it then it send email to that address
推荐答案
我们无法分辨 - 问题可能不在代码中,而是在调用它的代码中。
所以使用调试器:在第一行放置一个断点Sub和调试器点击时它会查看你作为recepientEmail
字符串传递的确切内容。
如果它不是你所期望的 - 我怀疑它不会 - 使用调用堆栈回顾你的代码,找出原因是什么。
但我们不能为你做任何事情 - 我们不这样做拥有其余的代码,因此我们无法运行它,因为我们没有您的数据为我们提供相同的值,所以它无济于事!
We can't tell - the problem probably isn't in that code but in the code that calls it.
So use the debugger: put a breakpoint on the first line of that Sub and when the debugger hits it look at exactly what you got passed as arecepientEmail
string.
If it's not what you expected - and I suspect it won't be - use the Call Stack to look back in your code to find out why it is what it is.
But we can't do any of that for you - we don't have the rest of your code, so we can't run it, and it wouldn't help anyway as we don't have your data to provide us with the same values!
这篇关于电子邮件。从数据库中解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!