How can I add two or more file attachments into the %Net.MailMessage
s status=msg.AttachFile("F:\MyDir","myFirstFile.pdf",1,.count)
s status=msg.AttachFile("F:\MyDir","mySecondFile.pdf",1,.count)
But it's not working at all...
Thank you in advance!
Discussion (2)0
Comments
First, should be so (AttachFile):
s status=msg.AttachFile("F:\MyDir","myFirstFile.pdf",1,,.count)
s status=msg.AttachFile("F:\MyDir","mySecondFile.pdf",1,,.count)Second, you did not specify the error text.
Try the following simple MAC-example, replacing the values with your own:
#include %systemInclude
new
try{
$$$AddAllRoleTemporaryInTry
new $namespace
set msg=##class(%Net.MailMessage).%New()
set msg.Subject="Subject"
set msg.From="from@domain"
do msg.To.Insert("to@domain")
do msg.TextData.Write("Hello!")
$$$ThrowOnError(msg.AttachFile("F:\MyDir","myFirstFile.pdf"))
$$$ThrowOnError(msg.AttachFile("F:\MyDir","mySecondFile.pdf"))
set smtp=##class(%Net.SMTP).%New()
set smtp.smtpserver="123.145.167.189"
$$$ThrowOnError(smtp.Send(msg))
}catch(ex){
write "Error ", ex.DisplayString(),!
}It's working! Thank you!