使用smtp.gmail.com向我的域名电子邮件地址发送电子邮件 [英] Send email using smtp.gmail.com to my domain email address

查看:284
本文介绍了使用smtp.gmail.com向我的域名电子邮件地址发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种方法,第一种是最简单的一种,如下所示,而第二种方法是格式化我的电子邮件内容,第二种方法调用另一种方法进行格式化,然后调用另一种方法进行smtp设置,第一种方法有效很好,它发送电子邮件到我的域名电子邮件地址,如omer@planrbme.com.pk,而第二种方法是不发送电子邮件到我的域名emil地址omer@planrbme.com.pk,它发送电子邮件给所有其他人但不发送给我域电子邮件地址。下面是两种方法,第一种方法是罚款,但第二种是向所有其他电子邮件地址发送电子邮件,除了我的域名电子邮件地址,为什么会这样。

第一种方法:



 私人  Sub  SendHtmlFormattedEmail(< span class =code-keyword> ByVal  recepientEmail 作为 字符串 ByVal  subject 作为 字符串 ByVal  body 作为 字符串
Dim mailMessage As System.Net.Mail.MailMessage = 系统。 Net.Mail.MailMessage
尝试
mailMessage.From = MailAddress(ConfigurationManager.AppSettings( UserName ))
mailMessage.Subject = subject
mailMessage.Body = body
mailMessage.IsBodyHtml = True
mailMessage。< span class =code-keyword> To .Add( New MailAddress(recepientEmail))
Dim 文件作为列表( HttpPostedFile)= DirectCast (缓存( Me .Key),列表( HttpPostedFile))
对于 每个文件 As HttpPostedFile 个文件中
mailMessage.Atta chments.Add(附件(file.InputStream,Path.GetFileName(file.FileName),file.ContentType))
下一步
Dim SMTP 作为 SmtpClient( smtp.gmail.com
SMTP.EnableSsl = True
SMTP.Credentials = System.Net.NetworkCredential( sweet.uet@gmail.com forgot123
SMTP.Port = 587
SMTP.Send(mailMessage) )
smtp.Send(mailMessage)
Catch ex As E xception
ex.Message.ToString()
结束 尝试
结束 Sub





第二种方法:

 私人  Sub  SendEmail()
GetUserIDEmail(会话( LoggedInUserId))
Dim Mail As MailMessage
尝试
Mail.IsBodyHtml = True
Dim MailText 作为 字符串 = 没什么
' Dim attachment As System.Net.Mail.Attachment
Mail.Subject = 报告提交者:&会话( LoggedInUserFullName)& & 用户类型:& GetUserTypeName( CInt (会话( UserTypes)))
MailText = MailText + < font face = verdana color =#000000 >& 亲爱的用户,& < / font>< br />< br />& Environment.NewLine
MailText = MailText + < font face = verdana color =#000000 > + & 我们很高兴地通知您,您的记录已被接受。< / font>& < br />< font face = Verdana > < br /> + AcceptComments& < / font> + Environment.NewLine
MailText = MailText + < font face = Verdana > < br />& 问候,& & < br />& 计划巴基斯坦RBME TEAM + < / font>& vbCrLf
Mail.IsBodyHtml = True

Mail.Body = MailText
Dim 文件作为列表( HttpPostedFile)= DirectCast (缓存( Me .Key),列表( HttpPostedFile))
对于 每个文件 As HttpPostedFile 个文件中
Mail.Attachments.Add(附件(file.InputStream,Path.GetFileName (file.FileName),file.ContentType))
下一步



$ Mail.From = MailAddress( sweet.uet@gmail.com
Dim SMTP As SmtpClient( smtp.gmail.com
SMTP.EnableSsl = True
SMTP.Credentials = System.Net.NetworkCredential( sweet.uet@gmail.com forgot123
SMTP.Port = 587
SMTP.Send(Mail)


Catch ex As 异常
ex.Message.ToString()

结束 尝试
结束 Sub





我的尝试:



也试过了

ServicePointManager.ServerCertificateValidationCallback = AddressOf OnValidateCertificate





ServicePointManager.Expect100Continue = True

解决方案

经过这么多讨论,似乎你错过了什么。



请参考我以前的答案,它给出了使用gmail发送邮件的完整代码。 从asp.net发送电子邮件至gmail [< a href =http://www.codeproject.com/Answers/321575/sending-email-to-gmail-from-asp-net#answer3target =_ blanktitle =New Window> ^

I have two methods the first one is the simplest one like below , while in second one i am formatting my email content , the second method calls another method to format and then it calls another method for smtp settings, the first method works fine it is sending email to my domain email address like omer@planrbme.com.pk while the second method is not sending email to my domain emil address omer@planrbme.com.pk , it is sending email to all others but not to my domain email address . below are the two methods the first one is fine but the second one is sending email to all other email address except my domain email address why it is so.
First 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.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
            Dim SMTP As New SmtpClient("smtp.gmail.com")
            SMTP.EnableSsl = True
            SMTP.Credentials = New System.Net.NetworkCredential("sweet.uet@gmail.com", "forgot123")
            SMTP.Port = 587
            SMTP.Send(mailMessage)
            smtp.Send(mailMessage)
        Catch ex As Exception
            ex.Message.ToString()
        End Try
    End Sub



Second Method:

Private Sub SendEmail()
                GetUserIDEmail(Session("LoggedInUserId"))
        Dim Mail As New MailMessage
        Try
            Mail.IsBodyHtml = True
            Dim MailText As String = Nothing
            'Dim attachment As System.Net.Mail.Attachment
            Mail.Subject = " Report Submitted By  : " & Session("LoggedInUserFullName") & "   " & "User Type :" & GetUserTypeName(CInt(Session("UserTypes")))
            MailText = MailText + "<font face="verdana" color="#000000">" & "Dear User, " & "</font><br /><br />" & Environment.NewLine
            MailText = MailText + "<font face="verdana" color="#000000">" + " " & "we are glad to inform you that your records  has accepted.</font>" & "<br /> ""<font face="Verdana"><br />" + AcceptComments & """</font> " + Environment.NewLine
            MailText = MailText + "<font face="Verdana"><br />" & " Regards," & "   " & "<br />" & "Plan Pakistan RBME TEAM" + "</font>" & vbCrLf
            Mail.IsBodyHtml = True

            Mail.Body = MailText
            Dim files As List(Of HttpPostedFile) = DirectCast(Cache(Me.Key), List(Of HttpPostedFile))
            For Each file As HttpPostedFile In files
                Mail.Attachments.Add(New Attachment(file.InputStream, Path.GetFileName(file.FileName), file.ContentType))
            Next



            Mail.From = New MailAddress("sweet.uet@gmail.com")
            Dim SMTP As New SmtpClient("smtp.gmail.com")
            SMTP.EnableSsl = True
            SMTP.Credentials = New System.Net.NetworkCredential("sweet.uet@gmail.com", "forgot123")
            SMTP.Port = 587
            SMTP.Send(Mail)


        Catch ex As Exception
            ex.Message.ToString()

        End Try
    End Sub



What I have tried:

have tried that too
ServicePointManager.ServerCertificateValidationCallback = AddressOf OnValidateCertificate


ServicePointManager.Expect100Continue = True

解决方案

After so much of discussion, seems like you are missing something.

Please refer my past answer, which gives the whole code to send mail using gmail. sending email to gmail from asp.net[^]


这篇关于使用smtp.gmail.com向我的域名电子邮件地址发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆