2012-12-05 47 views
0

我有一個類可以發送帶有多個附件的郵件,它使用gmail,但是我怎樣才能使用Outlook發送郵件?使用outlook代替gmail發送郵件vb.net 2010

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("[email protected]","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, _ 
          "[email protected]", _ 
          "[email protected]", _ 
          Filename _ 
         ) 
      SubjectText = "" 
      BodyText = "" 
      FromAddress = "" 
      ToAddress = "" 
      MessageBox.Show("Sent!", "HFB", MessageBoxButtons.OK, MessageBoxIcon.Information) 
     End Sub 

回答