VB.Net & Emails
-
.NET does not have MAPI controls . I used MAPI controls from VB6 'add 2 controls Microsoft MAPIMessages (call it MAPIMessages1) Microsoft MAPISession (call it MAPILogOn) (AxInterop.MSMAPI.dll, Interop.MSMAPI.dll) Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim msg As String msg = "This is a test email from Iouri." With Me .MAPILogOn.SignOn() ' use current user Do While .MAPILogOn.SessionID = 0 System.Windows.Forms.Application.DoEvents() ' need to wait until the new session is created Loop Call SendToEmail("someone@somewhere.com", msg) .MAPILogOn.SignOff() End With MsgBox("e-mail is sent") End Sub Private Sub SendToEmail(ByVal Email As String, ByVal msg As String) With MAPIMessages1 'create a new message and address it .SessionID = MAPILogOn.SessionID .Compose() .RecipDisplayName = Email .AddressResolveUI = True .RecipAddress = "smtp:" & Email .MsgSubject = "VB GENERATED E-MAIL" .MsgNoteText =msg .Send(False) End With End Sub End Class Regards, Dave
Dave Traister Software Engineer ComponentOne LLC www.ComponentOne.com