Send email with attachment from a specific url in C#

后端 未结 2 1741
-上瘾入骨i
-上瘾入骨i 2021-01-23 05:26

In my view, users can search for a document and once they get the result, they can click on its id and they can download the document from specific url based on id: http://test.

2条回答
  •  無奈伤痛
    2021-01-23 06:16

    Consider using Postal It's open source libriary for ASP.Net MVC allowing you to send emails very easy. For example to attach file you can use such code:

    dynamic email = new Email("Example");
    email.Attach(new Attachment("c:\\attachment.txt"));
    email.Send(); 
    

    Also you may want to use HangFire to send email in background, please take a look at the Sending Mail in Background with ASP.NET MVC

    Update: In order to get the PDF file path you can use Server.MapPath method to convert virtual path to the corresponding physical directory on the server.

提交回复
热议问题