Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vb.NET SmtpClient无法使用电子邮件发送电子邮件_Vb.net_Email_Smtp - Fatal编程技术网

vb.NET SmtpClient无法使用电子邮件发送电子邮件

vb.NET SmtpClient无法使用电子邮件发送电子邮件,vb.net,email,smtp,Vb.net,Email,Smtp,我正在尝试运行这段代码,将我正在处理的文件导出为PDF格式,并使用gmail通过电子邮件发送给“客户”。 我一直收到信息发送失败的消息,如果你能帮助阐明这一点,将不胜感激。 我也有明显的原因故意******我的电子邮件凭证 <MiCode(ControlScriptEventType.AfterInkAdded, "Email")> _ Public Sub Ctl_Email_AfterInkAdded(ByVal e As AfterInkAddedEventArgs) Ms

我正在尝试运行这段代码,将我正在处理的文件导出为PDF格式,并使用gmail通过电子邮件发送给“客户”。 我一直收到信息发送失败的消息,如果你能帮助阐明这一点,将不胜感激。 我也有明显的原因故意******我的电子邮件凭证

 <MiCode(ControlScriptEventType.AfterInkAdded, "Email")> _ 
Public Sub Ctl_Email_AfterInkAdded(ByVal e As AfterInkAddedEventArgs)
MsgBox("1")
    Dim EmailTo As String = _EmailAddress.Value
Dim EmailToName As String = "Client"
Dim EmailFrom As String = "******"
Dim EmailFromName As String = "WHSD" 


    Dim fileName As String = String.Empty
Dim erl As New System.Collections.Generic.List(Of ExportResult)

For Each er As ExportResult In _form.Validator.ExportResults
           erl.Add(er)
        fileName = System.IO.Path.GetFileNameWithoutExtension(er.ExpandedFilePath)
       Next

    Try
        Dim fromAddress As New MailAddress(EmailFrom, EmailFromName)
        Dim toAddress As New MailAddress(EmailTo, EmailToName)
        Using msg As New MailMessage(fromAddress, toAddress)
            msg.Body = "This will be the body of the message you are sending." & VbCrLf & "Thank you for your purchase."
            msg.Subject = (Me._form.Name & " (" & fileName & ")")

            ' Add the mail body - an HTML file attached to this form.
            For Each attData As AttachmentData In _form.Attachments
                If String.Compare(attData.Name, "Lead Generation.html") = 0 Then
                       msg.Body = System.Text.UTF8Encoding.UTF8.GetChars(attData.BinaryData())
                    msg.Body = msg.Body.Replace("[filename]", fileName)
                End If
            Next

            ' Add pdf/csv file attachments to mail - they are datapaths of the form.
            For Each er As ExportResult In erl
                If er.Success And ( er.DataPathName = "PDF" Or er.DataPathName = "CSV" ) Then
                    msg.Attachments.Add(New Attachment(er.ExpandedFilePath))
                End If
            Next       

            Dim client As New SmtpClient("aspmx.l.google.com", 25)
            'client.EnableSsl = True
            'client.Timeout = 10000
            client.DeliveryMethod = SmtpDeliveryMethod.Network
            client.UseDefaultCredentials = False
            client.Credentials = New NetworkCredential("********", "******")
            client.Send(msg)
            Me.RecordExportResult("Email", True, "Sent email", "Sent email to " & EmailToName & "(" & EmailTo & ")", "")
            MsgBox("Sent!")
        End Using
    Catch ex As Exception
        Me.RecordExportResult("Email", False, ex.Message, ex.Message, ex.Message)
        MsgBox(ex.Message)
    End Try

End Sub

看起来你正试图使用gmail作为你的邮件服务器,在这种情况下,你肯定需要使用SSL/TLS,并确保你的凭据如下

Google的SMTP服务器需要身份验证,下面介绍如何设置:

SMTP服务器,即发送邮件:SMTP.gmail.com SMTP用户名:您的 完整的Gmail或谷歌应用电子邮件地址,例如。example@gmail.com或 example@yourdomain.com SMTP密码:您的Gmail或Google应用程序 电子邮件密码 SMTP端口:465 需要SMTP TLS/SSL:是 要在您的Gmail或Google Apps Sent文件夹中存储传出电子邮件的副本,请登录您的Gmail或Google Apps电子邮件设置,然后: 单击“转发/IMAP”选项卡并向下滚动至IMAP访问部分:必须启用IMAP才能将电子邮件正确复制到“已发送”文件夹

注意:Google会自动将您通过其SMTP服务器发送的任何电子邮件的“发件人”行改写为您的Gmail或Google Apps电子邮件帐户设置中的默认“以电子邮件形式发送邮件”地址。您需要注意这种细微差别,因为从收件人的角度来看,它会影响电子邮件的显示,并且可能会影响某些程序的回复设置


解决方法:在您的谷歌电子邮件设置中,转到“帐户”选项卡/部分,将默认帐户设置为Gmail/谷歌应用程序帐户以外的帐户。这将导致Google的SMTP服务器重新写入“发件人”字段,并将您启用的任何地址作为默认的“以邮件方式发送”地址。

在方法的开头设置一个断点,然后逐步执行代码。然后你就会知道错误在哪一行,从这里你可以找到什么是空的/不等于它应该是什么。请遵循以下链接:@Mathemats不幸的是,我正在使用的软件没有调试器,我一直在到处放置消息框来测试它,到目前为止,它在For-Each-er导出中中断。。。。代码块