Link to home
Start Free TrialLog in
Avatar of tmack
tmack

asked on

Attachments using MAPI comtrol

I have an app I developed with VB 6.0 using the MAPI control. What I am trying to do is attach a document or file to an email that will be created from the app. I am lost on how to do this andy help would be appreciated. I also want to know how to send the mail message to mutiple persons(I.E a group or mutiple individuals, CC, BCC) I am using Outlook as my mail client.
Avatar of setiawan
setiawan

tmcak, just try like this
hope this helps

Private Sub Command1_Click()
    ' this command button is used to start a MAPI session, log on the
    '     the
    ' mail service, attach the created check summary text file to a n
    '     ew
    ' message, send the message and then close the session
    ' declare local variables here
    Dim strUserId As String
    Dim strPassword As String
    Dim strFileName As String
    Dim strFilePath As String
    ' set the mouse pointer to indicate the app is busy
    Screen.MousePointer = vbHourglass
    ' set the values for the file name and the file path
    strFileName = "sendmail.frm" ' this is where you would put any file attachments
    strFilePath = App.Path & "\"
    ' set the user name and password properties on the session contro
    '     l
    mapiLogOn.UserName = "user" ' network user name and password !
    mapiLogOn.Password = "testing"
    ' start a new email session
    mapiLogOn.SignOn


    Do While mapiLogOn.SessionID = 0


        DoEvents ' need to wait until the new session is created
        Loop

        'create a new message and address it
        MAPIMessages1.SessionID = mapiLogOn.SessionID
        MAPIMessages1.Compose
        MAPIMessages1.RecipDisplayName = "Danny Setiawan"
        MAPIMessages1.AddressResolveUI = True
        MAPIMessages1.ResolveName
        MAPIMessages1.RecipAddress = "smtp:ashiang@hotmail.com"
        ' note that I prefixed the address with "smtp". This is required
        '     by exchange
        ' server, or it does not know what service to use for outgoing ma
        '     il.
        MAPIMessages1.MsgSubject = "Test of the Email function"
        MAPIMessages1.MsgNoteText = " This is a test of the email function, If you" _
        & "receive this Then the program has worked successfully." & vbCrLf
        ' attaching the file
        MAPIMessages1.AttachmentPosition = Len(MAPIMessages1.MsgNoteText) - 1
        ' the line above places the attachment at the end of the text.
        MAPIMessages1.AttachmentPathName = strFilePath & strFileName
        ' now send the message
        MAPIMessages1.Send False
        mapiLogOn.SignOff
        MsgBox "File sent to specified receiptent."
        ' now set the mouse pointer back to normal
        Screen.MousePointer = vbNormal
End Sub

note : mapiLogOn is same as MAPISession1 ( rename   MAPISession1 to mapiLogOn

  regards
   
   danny
Avatar of tmack

ASKER

Setiawan;
This is great! Sorry I rejected your answer but I wanted to ask for a one
last thing(and I am adjusting points for this). I would also like to know
how I can send to more than one person. For example if I wanted to send to
Tom, Dick, and Harry. I have tried to do this several times(delimiting the
addresses with ';' but this doesnt work) but with out success. Also is there
a way if I just created a 'group' in outlook could I just call this and send
my message to those recipients? If you could just set me on the right path I
would appreciated it.
Thanks.
T
Tmack, I haven't try it and have no time to try it but It should be work

Const RECIPTYPE_TO = 1      
Const RECIPTYPE_CC = 2  
       
MapiMessages1.RecipIndex = 0                    'First recipient
      MapiMessages1.RecipType = RECIPTYPE_TO          'Recipient in TO line
      MapiMessages1.RecipDisplayName = "Tom"   'e-mail name
      MapiMessages1.RecipIndex = 1                  'add a second recipient
      MapiMessages1.RecipType = RECIPTYPE_TO        'Recipient in TO line
      MapiMessages1.RecipDisplayName = "Dick"     '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 = "Harry" 'e-mail name"
Avatar of tmack

ASKER

thanks!
I will test this and get back to ya, thanks again.....

T
ASKER CERTIFIED SOLUTION
Avatar of manojamin
manojamin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial