viewpoint-particle

Author Topic: Email using the System.Net.Mail class : hjow to add an attachment  (Read 4295 times)

Die

  • Newbie
  • *
  • Posts: 2
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

  • Pundit
  • *****
  • Posts: 935
Re: Email using the System.Net.Mail class : hjow to add an attachment
« Reply #1 on: December 11, 2013, 07:28:25 am »
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

  • Pundit
  • *****
  • Posts: 1014
    • Data & Stuff Inc.
Re: Email using the System.Net.Mail class : hjow to add an attachment
« Reply #2 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

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Deana F.
Technical Support
Wilson WindowWare Inc.

stanl

  • Pundit
  • *****
  • Posts: 935
Re: Email using the System.Net.Mail class : hjow to add an attachment
« Reply #4 on: December 12, 2013, 08:15:16 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

  • Pundit
  • *****
  • Posts: 1014
    • Data & Stuff Inc.
Re: Email using the System.Net.Mail class : hjow to add an attachment
« Reply #5 on: December 12, 2013, 08:49:13 am »
I know....I was partly affirming that what you posted would work but also trying to brighten your day...but apparently failed  :'(

Jim

Die

  • Newbie
  • *
  • Posts: 2
Re: Email using the System.Net.Mail class : hjow to add an attachment
« Reply #6 on: December 12, 2013, 11:31:12 pm »
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.