Email using the System.Net.Mail class : hjow to add an attachment

Started by Die, December 11, 2013, 03:27:38 AM

Previous topic - Next topic

Die

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?

stanl

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.






JTaylor

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

Deana

Deana F.
Technical Support
Wilson WindowWare Inc.

stanl

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

JTaylor

I know....I was partly affirming that what you posted would work but also trying to brighten your day...but apparently failed  :'(

Jim

Die

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.

SMF spam blocked by CleanTalk