ei,
would like to ask assistance if anyone knows how to use the MAPI control with VB, i have already seen basic codes but my question is what if we have an exchange server, i have encountered error when i tried the code
MAPISession1.SignOn
MAPIMessages1.Compose
MAPIMessages1.RecipAddress = "mhyke20_99@yahoo.com
MAPIMessages1.MsgSubject = "TEST"
MAPIMessages1.MsgNoteText = "Test Email"
MAPIMessages1.ResolveName
MAPIMessages1.Send
thanks in advance.
Mhyke
Comments
:
: MAPISession1.SignOn
: MAPIMessages1.Compose
: MAPIMessages1.RecipAddress = "mhyke20_99@yahoo.com
: MAPIMessages1.MsgSubject = "TEST"
: MAPIMessages1.MsgNoteText = "Test Email"
: MAPIMessages1.ResolveName
: MAPIMessages1.Send
:
: thanks in advance.
:
: Mhyke
:
This works on Groupwise, I have not tested on Exchange but the code was from Microsoft for Outlook. Microsoft left out a couple properties that caused it to hang but I revised it with info from my VB6 Black Book and error free ever since.
Dim sSendTo As String
Dim sSubject As String, sMessage As String
Dim sAttachName As String, sAttachPath As String
Private Sub cmdSend_Click()
sSendTo = "MyUser"
sSubject = "MySubject"
sMessage = "My message"
sAttachPath = "c: empMyFile.txt"
sAttachName = right(sAttachPath, InStrRev(sAttachPath, "") - 1)
SendMail 'USE MAPI CONTROL TO SEND EMAIL ATTACHMENT
End Sub
Private Sub SendMail()
'KB113033 How to Send a Mail Message Using Visual Basic MAPI Controls
'MAPI constants from CONSTANT.TXT file:
Const ATTACHTYPE_DATA = 0
Const RECIPTYPE_TO = 1
Const RECIPTYPE_CC = 2
On Error GoTo errh
'Open up a MAPI session:
Me.MAPIsession1.downloadmail = False 'revised - sending mail
Me.MAPIsession1.SignOn
'Point the MAPI messages control to the open MAPI session:
Me.MAPImessages1.SessionID = Me.MAPIsession1.SessionID
'Create a new message
Me.MAPImessages1.msgindex = -1 'revised
Me.MAPImessages1.Compose
'Set the subject of the message:
Me.MAPImessages1.MsgSubject = sSubject
'Set the message content:
Me.MAPImessages1.MsgNoteText = sMessage
'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.
Me.MAPImessages1.AttachmentPosition = 0
'Set the type of attachment:
Me.MAPImessages1.AttachmentType = ATTACHTYPE_DATA
'Set the icon title of attachment:
Me.MAPImessages1.AttachmentName = sAttachName
'Set the path and file name of the attachment:
Me.MAPImessages1.AttachmentPathName = sAttachPath
'Set the recipients
Me.MAPImessages1.RecipIndex = 0
Me.MAPImessages1.RecipType = RECIPTYPE_TO
Me.MAPImessages1.RecipDisplayName = sSendTo '4/22/03
'Me.MAPImessages1.RecipAddress = sSendTo
'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.
'Me.MAPImessages1.ResolveName 'comment out due to receiptent error w/ GW6.5 1/5/04
'Send the message:
Me.MAPImessages1.Send True 'revised
xit:
'Close MAPI mail session:
Me.MAPIsession1.SignOff
xit2:
DoCmd.Hourglass False
Exit Sub
errh:
If Err.Number = 32053 Then Resume xit2
MsgBox Err.Description, vbCritical, Err.Number
Resume xit
End Sub
[/code]
: :
: : MAPISession1.SignOn
: : MAPIMessages1.Compose
: : MAPIMessages1.RecipAddress = "mhyke20_99@yahoo.com
: : MAPIMessages1.MsgSubject = "TEST"
: : MAPIMessages1.MsgNoteText = "Test Email"
: : MAPIMessages1.ResolveName
: : MAPIMessages1.Send
: :
: : thanks in advance.
: :
: : Mhyke
: :
:
: This works on Groupwise, I have not tested on Exchange but the code was from Microsoft for Outlook. Microsoft left out a couple properties that caused it to hang but I revised it with info from my VB6 Black Book and error free ever since.
:
:
: Dim sSendTo As String
: Dim sSubject As String, sMessage As String
: Dim sAttachName As String, sAttachPath As String
:
: Private Sub cmdSend_Click()
: sSendTo = "MyUser"
: sSubject = "MySubject"
: sMessage = "My message"
: sAttachPath = "c: empMyFile.txt"
: sAttachName = right(sAttachPath, InStrRev(sAttachPath, "") - 1)
:
: SendMail 'USE MAPI CONTROL TO SEND EMAIL ATTACHMENT
: End Sub
:
:
: Private Sub SendMail()
: 'KB113033 How to Send a Mail Message Using Visual Basic MAPI Controls
: 'MAPI constants from CONSTANT.TXT file:
: Const ATTACHTYPE_DATA = 0
: Const RECIPTYPE_TO = 1
: Const RECIPTYPE_CC = 2
:
: On Error GoTo errh
:
: 'Open up a MAPI session:
: Me.MAPIsession1.downloadmail = False 'revised - sending mail
: Me.MAPIsession1.SignOn
: 'Point the MAPI messages control to the open MAPI session:
: Me.MAPImessages1.SessionID = Me.MAPIsession1.SessionID
:
: 'Create a new message
: Me.MAPImessages1.msgindex = -1 'revised
: Me.MAPImessages1.Compose
:
: 'Set the subject of the message:
: Me.MAPImessages1.MsgSubject = sSubject
: 'Set the message content:
: Me.MAPImessages1.MsgNoteText = sMessage
:
: '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.
: Me.MAPImessages1.AttachmentPosition = 0
: 'Set the type of attachment:
: Me.MAPImessages1.AttachmentType = ATTACHTYPE_DATA
: 'Set the icon title of attachment:
: Me.MAPImessages1.AttachmentName = sAttachName
: 'Set the path and file name of the attachment:
: Me.MAPImessages1.AttachmentPathName = sAttachPath
:
: 'Set the recipients
: Me.MAPImessages1.RecipIndex = 0
: Me.MAPImessages1.RecipType = RECIPTYPE_TO
: Me.MAPImessages1.RecipDisplayName = sSendTo '4/22/03
: 'Me.MAPImessages1.RecipAddress = sSendTo
:
: '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.
: 'Me.MAPImessages1.ResolveName 'comment out due to receiptent error w/ GW6.5 1/5/04
: 'Send the message:
: Me.MAPImessages1.Send True 'revised
:
: xit:
: 'Close MAPI mail session:
: Me.MAPIsession1.SignOff
: xit2:
: DoCmd.Hourglass False
: Exit Sub
:
: errh:
: If Err.Number = 32053 Then Resume xit2
: MsgBox Err.Description, vbCritical, Err.Number
: Resume xit
: End Sub
:
: [/code]
:
:
thank you so much for the reply. will try to work on this code. thanks again
sAttachName = right(sAttachPath, InStrRev(sAttachPath, "") - 1)
should be:
sAttachName = right(sAttachPath, len(sAttachPath)-InStrRev(sAttachPath, ""))
A very good solution that helped me very much, thank you