0

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.

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

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

1 Answer 1

1

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");
1
  • Great, that´s the solution.
    – Paul_412
    Feb 20, 2022 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.