Hi guys,
I've been racking my brain with similar issues related to MAPI, which when working to send e-mails is fairly effective, but is extremely fragile. I kept getting Error Code: 48389 run time errors.
I was having a problem signing in to a session
i.e. Form1.MAPISession1.Action = 1
I broke my legacy code down written by predeccessors about 50 pages long, to finally work out a control in vb6 components called 'DatabaseControl' from 'DatabaseControl.ocx' was conflicting with the MAPI controls. My advice to anyone trying to send an e-mail would be to check thier components - especially this one which will not work inconjunction with MAPI. Its best to replace this control with direct SQL statements to access database instead using ADO.
Below is full procedure used to send e-mails:
- Sub SendMail()
-
'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:
-
Form1.MAPISession1.Action = SESSION_SIGNON
-
'Point the MAPI messages control to the open MAPI session:
-
Form1.MAPIMessages1.SessionID = Form1.MAPISession1.SessionID
-
-
Form1.MAPIMessages1.Action = MESSAGE_COMPOSE 'Start a new message
-
-
'Set the subject of the message:
-
Form1.MAPIMessages1.MsgSubject = "This is the subject."
-
'Set the message content:
-
Form1.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.
-
Form1.MAPIMessages1.AttachmentPosition = 0
-
'Set the type of attachment:
-
Form1.MAPIMessages1.AttachmentType = ATTACHTYPE_DATA
-
'Set the icon title of attachment:
-
Form1.MAPIMessages1.AttachmentName = "System Configuration File"
-
'Set the path and file name of the attachment:
-
Form1.MAPIMessages1.AttachmentPathName = "C:\CONFIG.SYS"
-
-
'Set the recipients
-
Form1.MAPIMessages1.RecipIndex = 0 'First recipient
-
Form1.MAPIMessages1.RecipType = RECIPTYPE_TO 'Recipient in TO line
-
Form1.MAPIMessages1.RecipDisplayName = "eddyjawed@yahoo.com" 'e-mail name
-
'MAPIMessages1.RecipIndex = 1 'add a second recipient
-
'MAPIMessages1.RecipType = RECIPTYPE_TO 'Recipient in TO line
-
'MAPIMessages1.RecipDisplayName = "Tanya Lasagna" 'e-mail name
-
'MAPIMessages1.RecipIndex = 2 'Add a third recipient
-
'MAPIMessages1.RecipType = RECIPTYPE_CC 'Recipient in CC line
-
'MAPIMessages1.RecipDisplayName = "BlairAngelHair" 'e-mail name
-
'MAPIMessages1.RecipIndex = 3 'Add a fourth recipient
-
'MAPIMessages1.RecipType = RECIPTYPE_CC 'Recipient on CC Line
-
'MAPIMessages1.RecipDisplayName = "JoanieCannelloni" 'e-mail name"
-
-
'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.
-
Form1.MAPIMessages1.Action = MESSAGE_RESOLVENAME
-
'Send the message:
-
Form1.MAPIMessages1.Action = MESSAGE_SEND
-
End Sub
To get this to work, you need to create a form called form1, add a command button and then the two mapi controls ('session' and 'messages')....
Good luck ;)