Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EMAILING MULTIPLE ATTACHMENTS 1

Status
Not open for further replies.

DHart

Programmer
Oct 29, 2001
11
US
Recently, I received the below code as a solution to emailing word documents created in VisualFoxPro from existing reports.
Also let me say thanks to danceman, mgagnon and rgbean for their quick reponse and help.

MAPI control
with MAPIMessages1
.AttachmentIndex = 0
.AttachmentPosition = 0
.AttachmentPathName = ("c:\test1.txt")
.AttachmentIndex = 1
.AttachmentPosition = 1
.AttachmentPathName = ("c:\test2.txt")
endwith


My problem, since I am very new at this, how does that work exactly? Currently we use the below code to email a single attachment.

*************************************
procedure deliver_mail
if empty(m.subject) .or. empty(m.text) .or. empty(m.recipient)
wait window "Missing Email Header Data... Program Will Exit" timeout 1
return
else

***** Memory Variable Setup For Automatic Email ***********************
mprofile = "Microsoft Outlook" && Email Profile
***** m.subject = 'Visual Foxpro Automatic Mail' && Email Subject
***** m.text = 'This is a automatic email' && Email Information
***** m.recipient = 'Smith, John' && Who to send the Email to
***** m.attachment = 'l:\vfpmail.prg' && Email File Attachment
***********************************************************************
***********************************************************************
*Create a MAPI Session object then Logon. The Logon dialog can be
*bypassed by providing a valid ProfileName as the first parameter
*(as a string) to the Logon Method as seen below.
objSession = CREATEOBJECT("mapi.session")
objSession.Logon(mprofile)
*Create a new message in the Outbox and populate a few basic properties
objMessage = objSession.Outbox.Messages.Add
objMessage.Subject = m.subject
objMessage.Text = m.text
*Add an attachment (assumes "myfile.doc" exist in c:\)
if empty(m.attachment)
Wait Window " No Attachment To Send...." nowait
else
Wait Window "Attachment Will Be Sent...." nowait
objMessage.Attachments.Add(m.attachment, 0, 1, m.attachment)
endif
*Add a Recipient to the message we just created and resolve
objRecip = objMessage.Recipients.Add(m.recipient) && who it's to
objRecip.Resolve
*Send it
objMessage.Send
*Clean up then bail
objSession.Logoff
RELEASE objRecip, objMessage, objSession
endif


 
the example I gave you was using the activex controls. you are using the dll. So I believe this is what you want. the second parameter is the position in the index.

objMessage.Attachments.Add(m.attachment, 0, 1, m.attachment)
objMessage.Attachments.Add(m.attachment, 1, 1, m.attachment)
objMessage.Attachments.Add(m.attachment, 2, 1, m.attachment)

the order is
ADD([Name], [Position], [Type], [Source]) Attitude is Everything
 
Just an asside, I have found that with some email clients if the length of the email body is not at least as long as the attachement position you will get an error.

So if you are attaching 10 files, for example, make sure the body is at least 10 characters long if not pad it with spaces.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top