Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How can I do to send mails from Access?

kchokcho Member Posts: 6
Hi, I'm making an application in Access 2003 and my client wants to be able to send an e-mail from that.

Anybody knows how to do it?
Thanks

Comments

  • dokken2dokken2 Member Posts: 532
    : Hi, I'm making an application in Access 2003 and my client wants to be able to send an e-mail from that.
    :
    : Anybody knows how to do it?
    : Thanks
    :
    :

    microsoft has a knowledgebase article, unfortunately it omits a number of settings to get things working.

    you need to add 2 activex controls to your form- "Microsoft MapiSession" and "Microsoft MapiMessages", and add the SendMail code-

    [code]
    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 '4/22/03 vb6 black book
    Me.MAPISession1.SignOn
    'Point the MAPI messages control to the open MAPI session:
    Me.MAPIMessages1.SessionID = Me.MAPISession1.SessionID

    Me.MAPIMessages1.MsgIndex = -1 '4/22/03 vb6 black book
    Me.MAPIMessages1.Compose

    'Set the subject of the message:
    Me.MAPIMessages1.MsgSubject = "mail subject"
    'Set the message content:
    Me.MAPIMessages1.MsgNoteText = "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.
    Me.MAPIMessages1.AttachmentPosition = 0
    'Set the type of attachment:
    Me.MAPIMessages1.AttachmentType = ATTACHTYPE_DATA
    'Set the icon title of attachment:
    Me.MAPIMessages1.AttachmentName = "db1.mdb"
    'Set the path and file name of the attachment:
    Me.MAPIMessages1.AttachmentPathName = "d:db1.mdb"

    'Set the recipients
    Const iRecip = 2 '# of recipients
    Dim sSendTo(0 To iRecip) As String send-to names
    Dim i As Integer
    sSendTo(0) = "fred flintstone" 'send-to #1
    sSendTo(1) = "barney rubble" 'send-to #2

    For i = 0 To iRecip - 1
    Me.MAPIMessages1.RecipIndex = i ' 0
    Me.MAPIMessages1.RecipType = RECIPTYPE_TO
    Me.MAPIMessages1.RecipDisplayName = sSendTo(i)
    'Me.MAPImessages1.RecipAddress = sSendTo(i) '4/22/03 vb6 black book
    Next

    '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 for unknown recipient error w/ GW6.5 1/5/04
    'Send the message:
    Me.MAPIMessages1.Send True 'add true arg, 4/22/03 vb6 black book

    xit:
    'Close MAPI mail session:
    Me.MAPISession1.SignOff
    Exit Sub

    errh:
    MsgBox Err.Description, vbCritical, Err.Number
    Resume xit
    End Sub
    [/code]
  • kchokcho Member Posts: 6
    Thank You!


    : : Hi, I'm making an application in Access 2003 and my client wants to be able to send an e-mail from that.
    : :
    : : Anybody knows how to do it?
    : : Thanks
    : :
    : :
    :
    : microsoft has a knowledgebase article, unfortunately it omits a number of settings to get things working.
    :
    : you need to add 2 activex controls to your form- "Microsoft MapiSession" and "Microsoft MapiMessages", and add the SendMail code-
    :
    : [code]
    : 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 '4/22/03 vb6 black book
    : Me.MAPISession1.SignOn
    : 'Point the MAPI messages control to the open MAPI session:
    : Me.MAPIMessages1.SessionID = Me.MAPISession1.SessionID
    :
    : Me.MAPIMessages1.MsgIndex = -1 '4/22/03 vb6 black book
    : Me.MAPIMessages1.Compose
    :
    : 'Set the subject of the message:
    : Me.MAPIMessages1.MsgSubject = "mail subject"
    : 'Set the message content:
    : Me.MAPIMessages1.MsgNoteText = "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.
    : Me.MAPIMessages1.AttachmentPosition = 0
    : 'Set the type of attachment:
    : Me.MAPIMessages1.AttachmentType = ATTACHTYPE_DATA
    : 'Set the icon title of attachment:
    : Me.MAPIMessages1.AttachmentName = "db1.mdb"
    : 'Set the path and file name of the attachment:
    : Me.MAPIMessages1.AttachmentPathName = "d:db1.mdb"
    :
    : 'Set the recipients
    : Const iRecip = 2 '# of recipients
    : Dim sSendTo(0 To iRecip) As String send-to names
    : Dim i As Integer
    : sSendTo(0) = "fred flintstone" 'send-to #1
    : sSendTo(1) = "barney rubble" 'send-to #2
    :
    : For i = 0 To iRecip - 1
    : Me.MAPIMessages1.RecipIndex = i ' 0
    : Me.MAPIMessages1.RecipType = RECIPTYPE_TO
    : Me.MAPIMessages1.RecipDisplayName = sSendTo(i)
    : 'Me.MAPImessages1.RecipAddress = sSendTo(i) '4/22/03 vb6 black book
    : Next
    :
    : '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 for unknown recipient error w/ GW6.5 1/5/04
    : 'Send the message:
    : Me.MAPIMessages1.Send True 'add true arg, 4/22/03 vb6 black book
    :
    : xit:
    : 'Close MAPI mail session:
    : Me.MAPISession1.SignOff
    : Exit Sub
    :
    : errh:
    : MsgBox Err.Description, vbCritical, Err.Number
    : Resume xit
    : End Sub
    : [/code]
    :

Sign In or Register to comment.