I'm trying to send email using the system.net.mail class (based on http://forum.winbatch.com/index.php?topic=179.msg601#msg601). Without attachment it works.
I try to add an attachment using the command : Mailmessage.Attachments.Add("c:\temp\file.txt")
This creates winbatch error 1298: Ole: Error code not recognized
The extra error info gives :
COM/CLR Exception:
mscorlib
Method 'System.Net.Mail.AttachmentCollection.Add' not found
Anybody any idea how to add attachments (one or multiple) to an email?
I believe you are going to have to create an instance, something like
attachment = ObjectClrNew('System.Net.Mail.Attachment', file)
then
Mailmessage.Attachments.Add(attachment)
but I am sure it is a bit more complicated than this.
You are correct on the first part Stan. That will do the job.
Incorrect in that it is not more complicated :)
It can get more complicated though.
Jim
Check out the following code sample that includes an email file attachment: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/tsleft.web+WinBatch/dotNet/System_Net/Mail+Simple~SMTP~Email~Message.txt
Quote from: JTaylor on December 11, 2013, 07:55:09 AM
You are correct on the first part Stan. That will do the job.
Incorrect in that it is not more complicated :)
It can get more complicated though.
Jim
As I believe I said. The attachment class is overloaded, and it appears you often need to specify a MediaType when attaching pictures, or an avi. Also, there are touchy size limits
I know....I was partly affirming that what you posted would work but also trying to brighten your day...but apparently failed :'(
Jim
Stanl and Deana, thanks for the reply. The intermediate step with the creation of the instance solved my problem. Mails are going out with the attachment. Thanks.