How to send E-Mails from a vb program ,do i do it using outlook , are there any other settings to be done to send mails from a vb program
Printable View
How to send E-Mails from a vb program ,do i do it using outlook , are there any other settings to be done to send mails from a vb program
VB 5 and 6 comes with a MAPI control. You can find tutorials on the net.
See http://www.freevbcode.com/ShowCode.Asp?ID=109. This is a .dll that handles e-mails in VB. It will help you avoid the various headaches associated with MAPI.
If you have Outlook installed, an easy way is to create a class module called cOutlook like below. Then, you can somewhere else declare it
Public Mailer as New cOutlook
and then use the Mailer.SendMail (.....) method to send email.
If you have to use MAPI, then use the .dll the other guy recommends.
Option Explicit
Private Outlook As New Outlook.Application
Private mblnTerminateOutlook As Boolean
Private Sub Class_Initialize()
mblnTerminateOutlook = Outlook.ActiveExplorer Is Nothing
End Sub
Private Sub Class_Terminate()
If mblnTerminateOutlook Then Outlook.Quit
Set Outlook = Nothing
End Sub
Public Sub SendMail(strTo As String, strSubject As String, _
strMessageText As String, Optional strCC As String, _
Optional vntAttachmentPath As Variant)
Dim i As Integer
With Outlook
With .CreateItem(olMailItem)
.To = strTo
.CC = strCC
.Subject = strSubject
.Body = strMessageText & vbCrLf & vbCrLf
If IsArray(vntAttachmentPath) Then
For i = 0 To UBound(vntAttachmentPath)
.Attachments.Add vntAttachmentPath(i), , Len(.Body)
Next i
End If
.Send
End With
End With
End Sub