how to connect visual basic .net with microsoft exchange with free libraries posible?

PartySoft picture PartySoft · Mar 3, 2011 · Viewed 20.9k times · Source

Are there any free libraries for VB.net to use for connecting to a MS exchange server? I have found some paid ones but I'd rather not invest, so couln't find any free libraries.. I tried using java as a protocol layer for mapi but it wouldn't work

Answer

Rob P. picture Rob P. · Mar 3, 2011

What are you trying to accomplish?

I've had no trouble sending mail via my Exchange account using the regular SMTP client

    Public Shared Sub SendEmail(ByVal sFromAddress As String, _
                            ByVal sToAddress As String, _
                            ByVal sSMTPAddress As String, _
                            ByVal sUsername As String, _
                            ByVal sPassword As String, _
                            ByVal sOrderNo As String, _
                            ByVal sURL As String, _
                            ByVal iPort As Integer)

    Try
        Dim client As New SmtpClient(sSMTPAddress, iPort)
        client.UseDefaultCredentials = False
        client.Credentials = New System.Net.NetworkCredential(sUsername, sPassword)
        client.EnableSsl = True

        Dim mail As New MailMessage
        mail.To.Add(sToAddress)
        mail.From = New MailAddress(sFromAddress)
        mail.Subject = GetSubject(sOrderNo)
        mail.IsBodyHtml = True
        mail.Body = GetBody(sOrderNo, sURL)

        client.Send(mail)

    Catch ex As Exception
        MessageBox.Show("Error Sending E-mail!")
    End Try

End Sub

If you want to have a more meaningful interaction, I know you can accomplish a lot by using Microsoft.Office.Interop.Outlook. Check out http://msdn.microsoft.com/en-us/library/ms268893(VS.80).aspx for some more information.