cmarti
(Hey THIS is FUN)
2003-05-13 06:08 PM
Two attachments in an email sent from kix..

How can I add two attachments into an email? I pulled this code from this site..
Send mail through kix

Here's how I tried to do it, but it only attaches the first attachment.
code:
 
break on
:Email
$Root = CreateObject("Outlook.Application")
$MailItem = $Root.CreateItem(0)
$MailItem.Importance = 1
$MailItem.Subject = "Someheader"
$MailItem.To = "me@@mydomain.com"
$MailItem.Body = "SomeText for the body"
$MailItem.Attachments.Add("PathToFile1")
$MailItem.Attachments.Add("PathToFile2")
$MailItem.Body = "This is a test.@CRLF@CRLF"
$MailItem.Send
$Root = 0

Thanks in advance...L8tr..


Kdyer
(KiX Supporter)
2003-05-13 08:20 PM
Re: Two attachments in an email sent from kix..

We get some insight from -
Attachments Object

quote:

To ensure consistent results, always save an item before adding or removing objects in the Attachments collection of the item.

Try this:

code:
break on
:Email
$Root = CreateObject("Outlook.Application")
$MailItem = $Root.CreateItem(0)
$MailItem.Importance = 1
$MailItem.Subject = "Someheader"
$MailItem.To = "me@@mydomain.com"
$MailItem.Body = "SomeText for the body"
$MailItem.Attachments.Add("PathToFile1")
$MailItem.Save
$MailItem.Attachments.Add("PathToFile2")
$MailItem.Body = "This is a test.@CRLF@CRLF"
$MailItem.Send
$Root = 0

Please reply if this works as I will update the FAQ with this info.

HTH,

Kent

[ 13. May 2003, 21:00: Message edited by: kdyer ]


cmarti
(Hey THIS is FUN)
2003-05-13 08:30 PM
Re: Two attachments in an email sent from kix..

That worked like a charm I didn't have to put the save after the second attachments.add line though.

You are da man!!

Thanks.. [Big Grin]

[ 13. May 2003, 20:32: Message edited by: cmarti ]


Kdyer
(KiX Supporter)
2003-05-13 09:06 PM
Re: Two attachments in an email sent from kix..

cmarti,

Thanks and I have updated my above response as well as the FAQ.

Kent