by mahendra sharma (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 9th October 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)
send mail through vb6
Private Sub Command1_Click()
' to,cc,bcc,display true/false,mbody,msubject,attechment path'
mTo = "" ' Enter Receiver Add
mCc = "" ' Enter CC Address
mBcc = "" ' Enter BCC Address
mDisplay = True ' True = Display, False = Direct send
mBody = "Body Message" ' Body message
mSubject = "Subject Message" ' Subject message
mAttechment = "" ' filename with path ex. "c:\windows\aa.txt"
SendMessage mTo, mCc, mBcc, False, mBody, mSubject, mAttechment
End Sub
Sub SendMessage(sender As String, ccto As String, bccto As String, DisplayMsg As Boolean, mBody As String, mSubject As String, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(sender)
objOutlookRecip.Type = olTo
' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(ccto)
objOutlookRecip.Type = olCC
' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add(bccto)
objOutlookRecip.Type = olBCC
' Set the Subject, Body, and Importance of the message.
.Subject = mSubject
.Body = mBody
.Importance = olImportanceHigh 'High importance
' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub