Microsoft Developer Network > Forums Home > Feedback and Discussions Forums > MSDN Site Feedback > How can I send multiple attachments in email using VB.net 2008
Ask a questionAsk a question
 

QuestionHow can I send multiple attachments in email using VB.net 2008

  • Wednesday, October 28, 2009 6:01 PMMKTang Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Try

     

    ''Dim CCAddress As String = "Solog1@charterinternet.com"

     

    Dim MailStatus As New SmtpStatusCode

     

    ' Log intentions

     

    If Site = "OFC" Then

    LogData = LogData & vbCrLf &

    "Email To " & SiteToSend & " on " & strdate & vbCrLf

    LogData = LogData &

    "To Address= " & ToAddress & vbCrLf

    LogData = LogData &

    "CC Address= " & CCAddress & vbCrLf

     

    Else

     

    ''LogData = LogData & vbCrLf & "Server= " & Server & vbCrLf

    LogData = LogData &

    "To Address= " & ToAddress & vbCrLf

    LogData = LogData &

    "Email from " & " on " & strdate & vbCrLf

    LogData = LogData &

    "CC Address= " & CCAddress & vbCrLf

    LogData = LogData &

    "Body= " & body & vbCrLf

     

    End If

     

     

     

    Using message As New MailMessage(FromAddress, ToAddress, subject, body)

    Console.WriteLine(

    "To Address: " & ToAddress)

    message.CC.Add(CCAddress)

    message.Attachments.Add(

    New Attachment(FileToSend))

     

    ' Set mailServerName to be the name of our mail server for testing

     

    ' Build a Client using this server

     

    ''Dim mailServerName As String = Server

     

    Dim mailServerName As String = "smtp.charterinternet.com"

     

    Dim mailClient As New SmtpClient(mailServerName)

    mailClient.UseDefaultCredentials =

    True

     

    ''mailClient.Credentials = New NetworkCredential(User, Password)

     

    ''

    Console.WriteLine(

    "Sending File...")

    mailClient.Send(message)

     

    End Using

     

    Catch ex As SmtpException

    LogData = LogData &

    "SMTP Exception Fail" & ex.Message & " " & Now & vbCrLf

     

    If Debug = True Then

    Print(1,

    "SMTP Exception " & ex.Message & vbCrLf)

     

    End If

     

    GoTo Finish

     

    End Try

     

    ''Next