Attaching Image in the body of mail in C#

后端 未结 3 1664
一向
一向 2020-12-01 19:13

How can I attach an image in the body content . I have written the below code

System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
string         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 19:45

        string attachmentPath = Environment.CurrentDirectory + @"\test.png";
        Attachment inline = new Attachment(attachmentPath);
        inline.ContentDisposition.Inline = true;
        inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
        inline.ContentId = contentID;
        inline.ContentType.MediaType = "image/png";
        inline.ContentType.Name = Path.GetFileName(attachmentPath);
    
        message.Attachments.Add(inline);
    

    reference: Send an Email in C# with Inline attachments

提交回复
热议问题