Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Send attachments with MailKIt which comes from a website

I´m using asp.net with c#

I send emails with MailKit including pdf attachments.
These pdf files are at the moment on my local computer.
This works so far without any problems.
For the local files I specify the path like this.

builder.Attachments.Add(@"C:\files\06\attachment.pdf");

Now I have the problem that the pdf attachments have to be loaded directly from a website.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

i.e.: https://website.com/files/06/atachment.pdf

Is this possible with Mailkit?
How do I specify the path?

>Solution :

Include this namespace

using System.Net;

Download your files to a path using WebClient class

using (WebClient wc = new WebClient())
{
    wc.DownloadFile (
        // Param1 = Link of file
        new System.Uri("https://website.com/files/06/atachment.pdf"),
        // Param2 = Path to save
        @"D:\Images\atachment.pdf"
    );
}

and then attach as usual

builder.Attachments.Add(@"D:\Images\atachment.pdf");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading