How to embed an attachment in System.Net.Mail.mailMessage using the Body properties

I need to send an email with the application. No problem if I do it myself, but ...

Inside the company I work for, I need to go through a web service that expects email and bodies.

I know that the implementation of this service uses System.Web.mail.Mailmessage, perhaps something like this:

MailMessage mm = new MailMessage();
mm.to = email_;
mm.body = body_;
...

So, is there a way to create a string that will contain my binding so that I can send it to the web service?

THX

- Edition-- I have to use the "TheCompanyMail" class, which has 2 properties (to, body) and one method (send). This class is a proxy for the web service. This web service is the one that really sends mail. The problem is that I need to add an attachment to the mail and really don't know how to do it.

Example

File f = MyFuturAttachementFile;

TheComapyMail m = new TheCompanyMail();
m.to = "myCustomer@Company.com"
m.body = "Here is the file you're waiting for:"+f.ToString(); //this of course doesn't work !!!
m.send();

So, I am wondering if I can format the string of the body property to add an attachment?

+3
source share
3 answers

I’m not sure that I’m right, but, in my opinion, it is impossible to transfer attachments by adding them to a line in the message body. The main reason - not an argument - is safety. I don't think Microsoft can allow this class to behave like this ...

+1
source

, Attachements MailMessage.

- , , ?

0

You can create an HTML email address where the “attachment” is actually linked to download the file, rather than the actual email attachment.

0
source

Source: https://habr.com/ru/post/1759097/


All Articles