shaji_am
asked on
Sending E- mail from VB project
Hi,
I am finalising a VB project. Now I want to send an
e- mail from my project to one person with one message
when a specific condition is met. Is it possible?
Thanks and regards
Shaji
I am finalising a VB project. Now I want to send an
e- mail from my project to one person with one message
when a specific condition is met. Is it possible?
Thanks and regards
Shaji
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry ignore previous post it is 16 bit code using .VBX
shaji_am,
Before proceding further, please tend to all your 7 pending questions that you have not bothered to follow-up on. There are some dating back to April.
For the record:
Questions Asked 7
Last 10 Grades Given
Question Grading Record 0 Answers Graded / 0 Answers Received
Before proceding further, please tend to all your 7 pending questions that you have not bothered to follow-up on. There are some dating back to April.
For the record:
Questions Asked 7
Last 10 Grades Given
Question Grading Record 0 Answers Graded / 0 Answers Received
What is your email program?
If you have outlook
Option Explicit
Dim App As Object
Dim Itm As Object
Set App = CreateObject("Outlook.Appl ication")
Set Itm = App.CreateItem(0)
With Itm
.Subject = "A tip from vbCode Magician"
.To = "mail1@get2net.dk; mail2@get2net.dk"
.Body = "For tips and source visit vbCode Magician"
.Send
End With
from
http://www.vbecstasy.com/code.asp?cat=Network%2FInternet&id=45&catid=inet
Option Explicit
Dim App As Object
Dim Itm As Object
Set App = CreateObject("Outlook.Appl
Set Itm = App.CreateItem(0)
With Itm
.Subject = "A tip from vbCode Magician"
.To = "mail1@get2net.dk; mail2@get2net.dk"
.Body = "For tips and source visit vbCode Magician"
.Send
End With
from
http://www.vbecstasy.com/code.asp?cat=Network%2FInternet&id=45&catid=inet
Here is some other demo code
http://www.vbsquare.com/demos/sendmail-demo.zip
http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=100
http://www.vbsquare.com/demos/sendmail-demo.zip
http://www.vb2themax.com/Item.asp?PageID=TipBank&ID=100
See this great free tool:
You don't need to worry about which client mail application is already installed...
http://www.freevbcode.com/ShowCode.Asp?ID=109
You don't need to worry about which client mail application is already installed...
http://www.freevbcode.com/ShowCode.Asp?ID=109
<listening..>
This is from a test program I wrote:
======================
Form1:
======================
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC- 0000F8754D A1}#2.0#0" ; "MsComCtl.ocx"
Begin VB.Form Form1
Caption = "MAPI test"
ClientHeight = 5790
ClientLeft = 60
ClientTop = 345
ClientWidth = 9660
LinkTopic = "Form1"
ScaleHeight = 5790
ScaleWidth = 9660
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "&Attachments"
Height = 390
Left = 8175
TabIndex = 10
Top = 2775
Width = 1215
End
Begin MSComctlLib.ListView lvInbox
Height = 3315
Left = 900
TabIndex = 8
Top = 2250
Width = 7065
_ExtentX = 12462
_ExtentY = 5847
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
FullRowSelect = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 3
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-0 0C0F028362 8}
Text = "From"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-0 0C0F028362 8}
SubItemIndex = 1
Text = "Subject"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-0 0C0F028362 8}
SubItemIndex = 2
Text = "Attachments"
Object.Width = 2540
EndProperty
End
Begin VB.TextBox txtBody
Height = 990
Left = 900
MultiLine = -1 'True
TabIndex = 6
Top = 900
Width = 7065
End
Begin VB.TextBox txtTo
Height = 315
Left = 900
TabIndex = 5
Top = 150
Width = 7065
End
Begin VB.TextBox txtSubject
Height = 315
Left = 900
TabIndex = 4
Top = 525
Width = 7065
End
Begin VB.CommandButton Command2
Caption = "&Get Inbox"
Height = 390
Left = 8175
TabIndex = 1
Top = 2250
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "&Send"
Height = 390
Left = 8175
TabIndex = 0
Top = 150
Width = 1215
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "Inbox:"
Height = 195
Left = 150
TabIndex = 9
Top = 2325
Width = 435
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "Body:"
Height = 195
Left = 150
TabIndex = 7
Top = 975
Width = 405
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Subject:"
Height = 195
Left = 150
TabIndex = 3
Top = 600
Width = 585
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "To:"
Height = 195
Left = 150
TabIndex = 2
Top = 225
Width = 240
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim oOutlook As Outlook.Application
Dim oFolder As Outlook.MAPIFolder
Dim oMailitem As Outlook.MailItem
Private Sub Command1_Click()
Dim oMessage As Outlook.MailItem
Set oMessage = oOutlook.CreateItem(olMail Item)
With oMessage
.To = txtTo.Text
.Subject = txtSubject.Text
.Body = txtBody.Text
.Send
End With
Set oMessage = Nothing
End Sub
Private Sub Command2_Click()
Dim sAtt As String
Dim lst As ListItem
Set oFolder = oOutlook.GetNamespace("MAP I").GetDef aultFolder (olFolderI nbox)
For Each oMailitem In oFolder.Items
Set lst = lvInbox.ListItems.Add(, , oMailitem.SenderName)
lst.SubItems(1) = oMailitem.Subject
If oMailitem.Attachments.Coun t > 0 Then
lst.SubItems(2) = CStr(oMailitem.Attachments .Count)
End If
lst.SubItems(3) = oMailitem.EntryID
Next oMailitem
End Sub
Private Sub Command3_Click()
Dim frm As Form2
Dim oAtt As Attachment
If lvInbox.SelectedItem.Index = 0 Then
MsgBox "Select a message first !", vbCritical
Exit Sub
End If
If Len(lvInbox.SelectedItem.S ubItems(2) ) = 0 Then
MsgBox "This message contains no attachment(s) !", vbInformation
Exit Sub
End If
For Each oMailitem In oFolder.Items
If oMailitem.EntryID = lvInbox.SelectedItem.SubIt ems(3) Then
Set frm = New Form2
frm.lblMessage.Caption = oMailitem.Subject
For Each oAtt In oMailitem.Attachments
frm.lstAtt.AddItem oAtt.FileName
Next oAtt
frm.Show vbModal
Unload frm
End If
Next oMailitem
Set oAtt = Nothing
End Sub
Private Sub Form_Load()
Dim lWidth As Long
lWidth = (lvInbox.Width - 100) / 4
Set oOutlook = New Outlook.Application
With lvInbox
.View = lvwReport
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "From", lWidth
.ColumnHeaders.Add , , "Subject", lWidth * 2
.ColumnHeaders.Add , , "Attachments #", lWidth
.ColumnHeaders.Add , , "ID", 0
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
'oOutlook.Quit
Set oMailitem = Nothing
Set oFolder = Nothing
Set oOutlook = Nothing
End Sub
=========================
Form2:
=========================
VERSION 5.00
Begin VB.Form Form2
BorderStyle = 3 'Fixed Dialog
Caption = "Message"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Begin VB.ListBox lstAtt
Height = 2205
Left = 225
TabIndex = 0
Top = 675
Width = 4215
End
Begin VB.Label lblMessage
Caption = "#"
Height = 390
Left = 225
TabIndex = 1
Top = 150
Width = 4215
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
========================== =
Project:
========================== =
Type=Exe
Reference=*\G{00020430-000 0-0000-C00 0-00000000 0046}#2.0# 0#..\..\.. \..\WINNT\ System32\s tdole2.tlb #OLE Automation
Reference=*\G{00062FFF-000 0-0000-C00 0-00000000 0046}#9.0# 0#..\..\.. \..\Progra m Files\Microsoft Office\Office\msoutl9.olb# Microsoft Outlook 9.0 Object Library
Form=Form1.frm
Object={831FDD16-0C5C-11D2 -A9FC-0000 F8754DA1}# 2.0#0; MsComCtl.ocx
Form=Form2.frm
Startup="Form1"
Command32=""
Name="MailMAPItest"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName=""
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1
D'Mzzl!
RoverM
======================
Form1:
======================
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-
Begin VB.Form Form1
Caption = "MAPI test"
ClientHeight = 5790
ClientLeft = 60
ClientTop = 345
ClientWidth = 9660
LinkTopic = "Form1"
ScaleHeight = 5790
ScaleWidth = 9660
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton Command3
Caption = "&Attachments"
Height = 390
Left = 8175
TabIndex = 10
Top = 2775
Width = 1215
End
Begin MSComctlLib.ListView lvInbox
Height = 3315
Left = 900
TabIndex = 8
Top = 2250
Width = 7065
_ExtentX = 12462
_ExtentY = 5847
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
FullRowSelect = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 3
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-0
Text = "From"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-0
SubItemIndex = 1
Text = "Subject"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-0
SubItemIndex = 2
Text = "Attachments"
Object.Width = 2540
EndProperty
End
Begin VB.TextBox txtBody
Height = 990
Left = 900
MultiLine = -1 'True
TabIndex = 6
Top = 900
Width = 7065
End
Begin VB.TextBox txtTo
Height = 315
Left = 900
TabIndex = 5
Top = 150
Width = 7065
End
Begin VB.TextBox txtSubject
Height = 315
Left = 900
TabIndex = 4
Top = 525
Width = 7065
End
Begin VB.CommandButton Command2
Caption = "&Get Inbox"
Height = 390
Left = 8175
TabIndex = 1
Top = 2250
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "&Send"
Height = 390
Left = 8175
TabIndex = 0
Top = 150
Width = 1215
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "Inbox:"
Height = 195
Left = 150
TabIndex = 9
Top = 2325
Width = 435
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "Body:"
Height = 195
Left = 150
TabIndex = 7
Top = 975
Width = 405
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "Subject:"
Height = 195
Left = 150
TabIndex = 3
Top = 600
Width = 585
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "To:"
Height = 195
Left = 150
TabIndex = 2
Top = 225
Width = 240
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim oOutlook As Outlook.Application
Dim oFolder As Outlook.MAPIFolder
Dim oMailitem As Outlook.MailItem
Private Sub Command1_Click()
Dim oMessage As Outlook.MailItem
Set oMessage = oOutlook.CreateItem(olMail
With oMessage
.To = txtTo.Text
.Subject = txtSubject.Text
.Body = txtBody.Text
.Send
End With
Set oMessage = Nothing
End Sub
Private Sub Command2_Click()
Dim sAtt As String
Dim lst As ListItem
Set oFolder = oOutlook.GetNamespace("MAP
For Each oMailitem In oFolder.Items
Set lst = lvInbox.ListItems.Add(, , oMailitem.SenderName)
lst.SubItems(1) = oMailitem.Subject
If oMailitem.Attachments.Coun
lst.SubItems(2) = CStr(oMailitem.Attachments
End If
lst.SubItems(3) = oMailitem.EntryID
Next oMailitem
End Sub
Private Sub Command3_Click()
Dim frm As Form2
Dim oAtt As Attachment
If lvInbox.SelectedItem.Index
MsgBox "Select a message first !", vbCritical
Exit Sub
End If
If Len(lvInbox.SelectedItem.S
MsgBox "This message contains no attachment(s) !", vbInformation
Exit Sub
End If
For Each oMailitem In oFolder.Items
If oMailitem.EntryID = lvInbox.SelectedItem.SubIt
Set frm = New Form2
frm.lblMessage.Caption = oMailitem.Subject
For Each oAtt In oMailitem.Attachments
frm.lstAtt.AddItem oAtt.FileName
Next oAtt
frm.Show vbModal
Unload frm
End If
Next oMailitem
Set oAtt = Nothing
End Sub
Private Sub Form_Load()
Dim lWidth As Long
lWidth = (lvInbox.Width - 100) / 4
Set oOutlook = New Outlook.Application
With lvInbox
.View = lvwReport
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "From", lWidth
.ColumnHeaders.Add , , "Subject", lWidth * 2
.ColumnHeaders.Add , , "Attachments #", lWidth
.ColumnHeaders.Add , , "ID", 0
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
'oOutlook.Quit
Set oMailitem = Nothing
Set oFolder = Nothing
Set oOutlook = Nothing
End Sub
=========================
Form2:
=========================
VERSION 5.00
Begin VB.Form Form2
BorderStyle = 3 'Fixed Dialog
Caption = "Message"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Begin VB.ListBox lstAtt
Height = 2205
Left = 225
TabIndex = 0
Top = 675
Width = 4215
End
Begin VB.Label lblMessage
Caption = "#"
Height = 390
Left = 225
TabIndex = 1
Top = 150
Width = 4215
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
==========================
Project:
==========================
Type=Exe
Reference=*\G{00020430-000
Reference=*\G{00062FFF-000
Form=Form1.frm
Object={831FDD16-0C5C-11D2
Form=Form2.frm
Startup="Form1"
Command32=""
Name="MailMAPItest"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName=""
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1
[MS Transaction Server]
AutoRefresh=1
D'Mzzl!
RoverM
Hi!
Here's some examples for you over the net:
Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=9418&strZipAccessCode=ODE%5F94182363
Description: With this program, you can send emails with multiple file attachement using MS winsock control. Heavily commented. Please don't forget to vote!!
Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=10505&strZipAccessCode=ODE%5F105057258
Description: Are you tired of Outlook and Outlook Express hanging your machine, and letting the KAK virus in? Well, I am too, so in response, I made EZMailer, a simple email program that sends and receives mail, PERIOD. It doesn't attempt to interpret or auto-execute ...(description truncated
Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=4796&strZipAccessCode=mail47960542
Description: Email with attachments, Progress Bar, Drag & Drop
Should a 'specific condition' occur at any part of the day, use a timer, set it to interval say... 5000, enabled property set to True. In the timer, add the code to check for the condition. If the condition is met, then use any of the above codes to send an email : )
That's it!
glass cookie : )
Here's some examples for you over the net:
Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=9418&strZipAccessCode=ODE%5F94182363
Description: With this program, you can send emails with multiple file attachement using MS winsock control. Heavily commented. Please don't forget to vote!!
Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=10505&strZipAccessCode=ODE%5F105057258
Description: Are you tired of Outlook and Outlook Express hanging your machine, and letting the KAK virus in? Well, I am too, so in response, I made EZMailer, a simple email program that sends and receives mail, PERIOD. It doesn't attempt to interpret or auto-execute ...(description truncated
Download...
http://www.planetsourcecode.com/vb/scripts/ShowZip.asp?lngWId=1&lngCodeId=4796&strZipAccessCode=mail47960542
Description: Email with attachments, Progress Bar, Drag & Drop
Should a 'specific condition' occur at any part of the day, use a timer, set it to interval say... 5000, enabled property set to True. In the timer, add the code to check for the condition. If the condition is met, then use any of the above codes to send an email : )
That's it!
glass cookie : )
Hi shaji_am,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept appari's comment(s) as an answer.
shaji_am, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Accept appari's comment(s) as an answer.
shaji_am, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you. DO NOT accept this comment as an answer.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
EXPERTS,
While under almost every circumstance, DanRollins has done an incredible job of cleaning up this topic area, in this particular instance, I think he's slipped. appari, in a comment following his initial post, indicates that his/her post should be ignored.
Can I get a suggestion for resolving this question, please?
Netminder
CS Moderator
While under almost every circumstance, DanRollins has done an incredible job of cleaning up this topic area, in this particular instance, I think he's slipped. appari, in a comment following his initial post, indicates that his/her post should be ignored.
Can I get a suggestion for resolving this question, please?
Netminder
CS Moderator
Netminder,
Actually what appari says is to ignore his/her previous posts, but his/her first post is still relevant. So if Dan was referring to the first post, than he is correct.
However, I should add that due to the lack of informatoin in the original question and no follow-up from the questioner, it is hard to know what is the best answer. So, you could concievably split between:
appari
xSinbad
Richie_Simonetti
roverm
Anthony
Actually what appari says is to ignore his/her previous posts, but his/her first post is still relevant. So if Dan was referring to the first post, than he is correct.
However, I should add that due to the lack of informatoin in the original question and no follow-up from the questioner, it is hard to know what is the best answer. So, you could concievably split between:
appari
xSinbad
Richie_Simonetti
roverm
Anthony
<sigh>
acperkins,
I can see you've gone over to the Dark Side, inhabited by the Evil Twisted SPLITLizard, aka COBOLdinosaur...
<grin>
Netminder
acperkins,
I can see you've gone over to the Dark Side, inhabited by the Evil Twisted SPLITLizard, aka COBOLdinosaur...
<grin>
Netminder
Force-accepted, per recommendation.
Richie_Simonetti: points for you at https://www.experts-exchange.com/questions/20341396/For-Richie-Simonetti-re-20181303.html
xSinbad: points for you at https://www.experts-exchange.com/questions/20341397/For-xSinbad-re-20181303.html
roverm: points for you at https://www.experts-exchange.com/questions/20341399/For-roverm-re-20181303.html
Netminder
CS Moderator
Richie_Simonetti: points for you at https://www.experts-exchange.com/questions/20341396/For-Richie-Simonetti-re-20181303.html
xSinbad: points for you at https://www.experts-exchange.com/questions/20341397/For-xSinbad-re-20181303.html
roverm: points for you at https://www.experts-exchange.com/questions/20341399/For-roverm-re-20181303.html
Netminder
CS Moderator
Netminder,
Sorry about the extra work. But you did not have to take my word for it <g> ...
Anthony
Sorry about the extra work. But you did not have to take my word for it <g> ...
Anthony
Anthony,
Denial is the first symptom... but we'll see if we can save you... <laughing>
N
Denial is the first symptom... but we'll see if we can save you... <laughing>
N
1. Start a new project in Visual Basic. Form1 is created by default.
2. Add MSMAPI.VBX to the project.
3. Add a MAPI session control (MAPISession1) and a MAPI message control
(MAPIMessages1) to the form.
4. Add a command button (Command1) to the form.
5. Put the following code in the command button click event.
Sub Command1_Click ()
'MAPI constants from CONSTANT.TXT file:
Const SESSION_SIGNON = 1
Const MESSAGE_COMPOSE = 6
Const ATTACHTYPE_DATA = 0
Const RECIPTYPE_TO = 1
Const RECIPTYPE_CC = 2
Const MESSAGE_RESOLVENAME = 13
Const MESSAGE_SEND = 3
Const SESSION_SIGNOFF = 2
'Open up a MAPI session:
MapiSession1.Action = SESSION_SIGNON
'Point the MAPI messages control to the open MAPI session:
MapiMessages1.SessionID = form1.MapiSession1.Session
MapiMessages1.Action = MESSAGE_COMPOSE 'Start a new message
'Set the subject of the message:
MapiMessages1.MsgSubject = "This is the subject."
'Set the message content:
MapiMessages1.MsgNoteText = "This is the mail message."
'The following four lines of code add an attachment to the message,
'and set the character position within the MsgNoteText where the
'attachment icon will appear. A value of 0 means the attachment will
'replace the first character in the MsgNoteText. You must have at
'least one character in the MsgNoteText to be able to attach a file.
MapiMessages1.AttachmentPo
'Set the type of attachment:
MapiMessages1.AttachmentTy
'Set the icon title of attachment:
MapiMessages1.AttachmentNa
'Set the path and file name of the attachment:
MapiMessages1.AttachmentPa
'Set the recipients
MapiMessages1.RecipIndex = 0 'First recipient
MapiMessages1.RecipType = RECIPTYPE_TO 'Recipient in TO line
MapiMessages1.RecipDisplay
MapiMessages1.RecipIndex = 1 'add a second recipient
MapiMessages1.RecipType = RECIPTYPE_TO 'Recipient in TO line
MapiMessages1.RecipDisplay
MapiMessages1.RecipIndex = 2 'Add a third recipient
MapiMessages1.RecipType = RECIPTYPE_CC 'Recipient in CC line
MapiMessages1.RecipDisplay
MapiMessages1.RecipIndex = 3 'Add a fourth recipient
MapiMessages1.RecipType = RECIPTYPE_CC 'Recipient on CC Line
MapiMessages1.RecipDisplay
'MESSAGE_RESOLVENAME checks to ensure the recipient is valid and puts
'the recipient address in MapiMessages1.RecipAddress
'If the E-Mail name is not valid, a trappable error will occur.
MapiMessages1.Action = MESSAGE_RESOLVENAME
'Send the message:
MapiMessages1.Action = MESSAGE_SEND
'Close MAPI mail session:
MapiSession1.Action = SESSION_SIGNOFF
End Sub
6. Save the project.
7. Run the code, and click the command button.