Unable to bind the inline image into body content using FluentMail.SMTP
See original GitHub issueHi,
I’m trying to bind an embedded image to the mail body content.
Below is my code:
private void SendEmailWithInlineImages_FluentEmail()
{
try
{
//var assembly = Assembly.GetExecutingAssembly();
//var stream = assembly.GetManifestResourceStream(@"C:\Users\a.b\Downloads\FluentLogo.png");
//stream.Flush();
//stream.Seek(0, SeekOrigin.Begin);
//Setup Default sender befault sending the email.
System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient
{
Host = "smtp.office365.com",
Port = 587,
EnableSsl = true,
Credentials = new System.Net.NetworkCredential("a.b@gmail.com", "12345")
};
Email.DefaultSender = new SmtpSender(smtpClient);
Email.DefaultRenderer = new RazorRenderer();
string imagePath = @"C:\Users\pratik.soni\Downloads\FluentLogo.png";
var attachment = new Core.Models.Attachment()
{
IsInline = true,
Data = new FileStream(imagePath, FileMode.Open, FileAccess.Read),
ContentType = "image/png",
Filename = "FluentLogo.png"
};
var email = Email
.From("a.b@yahoo.com")
.To("a.b@gmai.com")
.Subject("Test with embadded image")
.Body("<html>Inline image here: <img src=\"cid:FluentLogo.png\">" +
"<p>You should see an image without an attachment, or without a download prompt, dependig on the email client.</p></html>", true)
.Attach(attachment);
email.Send();
}
catch (Exception ex)
{
throw;
}
}
But with this code, it is getting adding this image as an attachment rather than setting it up as an inline embedded image.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8
Top Results From Across the Web
Unable to send embedded image in email using FluentEmail
I'm using FluentEmail in ASP.NET core 2.0 class library which will be sending the Email notification. Below is the sample code I have...
Read more >Send HTML Emails with Attachments using FluentEmail, C# ...
Send HTML emails with images and buttons using SMTP and your free Gmail ... NET 5.0 sample app 3:01 - Adding FluentEmail Packages...
Read more >Send Email with Embedded Images in C#
To attach embedded images/pictures, SmtpMail.ImportHtmlBody and SmtpMail.ImportHtml methods are strongly recommended. With these methods, you don't have to ...
Read more >Send email in ASP.NET C# [2023 Tutorial with Code ...
NET C# using SMTP server? How to send emails in ASP.NET C# using an API? How to send an HTML email in ASP.NET...
Read more >Send Emails with ASP.NET Core in 5 EASY Steps - Guide
Step 1 – Create a New ASP.NET Core Project · Step 2 – Add the Required Mail Models · Step 3 – Configure...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am able to send inline an image using CID and SMTP. I did it in the following manner (found how to do it from the Unit Tests in the PR for Mailgun):
Not sure this is the best way, but it does it. Outlook does show an attachment icon, but it doesn’t force you to download images before showing it.
and in my Razor file I just have:
<img src="cid:logo.png">
My only issue is I couldn’t really find any documentation on any of this.
@zimmer62 Thanks for posting this. You are right, multipart/related in the eml shows up in Papercut SMTP now.
Is this an issue with Papercut, or FluentEmail? Why and when should we use multipart/related over multipart/mixed?
Thanks!