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
Email 使用outlook而不是gmail发送邮件vb.net 2010_Email_Vb.net 2010 - Fatal编程技术网

Email 使用outlook而不是gmail发送邮件vb.net 2010

Email 使用outlook而不是gmail发送邮件vb.net 2010,email,vb.net-2010,Email,Vb.net 2010,我有一个类可以发送带有多个附件的电子邮件,它使用gmail,但我如何使用Outlook发送电子邮件 Imports System.Net.Mail Imports System.Net.Mime Public Sub SendThis(ByVal SubjectText As String, _ ByVal BodyText As String, _ By

我有一个类可以发送带有多个附件的电子邮件,它使用gmail,但我如何使用Outlook发送电子邮件

   Imports System.Net.Mail
    Imports System.Net.Mime


    Public Sub SendThis(ByVal SubjectText As String, _
                             ByVal BodyText As String, _
                             ByVal FromAddress As String, _
                             ByVal ToAddress As String, _
                             Optional ByVal FileName As Collection = Nothing _
                             )
            Try
                Dim email As New Net.Mail.MailMessage(FromAddress, ToAddress)
                email.Subject = SubjectText
                email.Body = BodyText
                If Not FileName Is Nothing Then
                    For Each Name As String In FileName
                        Dim attach As New Net.Mail.Attachment(Name) 'Includes Path
                        email.Attachments.Add(attach)
                    Next
                    For Each At As Attachment In email.Attachments
                        At.TransferEncoding() = Net.Mime.TransferEncoding.Base64
                    Next
                End If
                Dim TheSmtp As New SmtpClient(YourSmtpServerName, 587)
                TheSmtp.Credentials = New Net.NetworkCredential("abc@gmail.com","MYPASS")
                TheSmtp.DeliveryMethod = SmtpDeliveryMethod.Network
                TheSmtp.Send(email)
                email.Attachments.Clear()
                TheSmtp = Nothing
                email = Nothing    
            Catch ex As Exception
                MessageBox.Show("Error: " & ex.Message, "HFB", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End Try
        End Sub
我调用函数如下:

      Private Sub BtnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click
            Dim BodyText As String
            Dim SubjectText As String
            Dim FromAddress As String
            Dim ToAddress As String
            Dim Filename As New Collection
            If Me.LstBxAttach.Items.Count > 0 Then
                For Each TheItem As String In LstBxAttach.Items
                    Filename.Add(TheItem)
                Next
            End If
            SubjectText = Me.TbSubject.Text
            BodyText = Me.TbBody.Text
            SendThis(SubjectText, _
                          BodyText, _
                          "from@example.com", _
                          "to@example.com", _
                          Filename _
                          )
            SubjectText = ""
            BodyText = ""
            FromAddress = ""
            ToAddress = ""
            MessageBox.Show("Sent!", "HFB", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Sub
您可以使用。该对象允许您连接到Outlook;要发送电子邮件,您需要创建一个对象,填充相关属性,并调用其方法