MimeMessage shows empty body in email in C#? - c#-4.0

I want to show html body in mail, I was sending mail through SMTP server using windows service. I write the request in a file & pass this file to MIME.Load() method to read that file and extract the data from that file, but here I get body in plain text format, & so empty body shows when actual email sent. I code for this as below, I use C# for coding
var message = MimeMessage.Load(emailFile);
I have html body but when I checked this message it gives me only plain text and does not shows its html version. I don't understand here how to set or change plain text body to html body in Mime. Does anyone knows about the solution. Thanks

Related

How to remove 'View Entire Message' option in gmail sent using sendgrid

In my current project, we are sending some user chosen services to the mail address provided in input.
We are using a HTML file to format the services and copying this html template to 'mail.Body' before sending the email.
The emails are sent using Sendgrid
When recieving this in gmail ,only for some clients (Set-A) ,even for short email '[Message clipped] View entire message' is shown at the bottom of the email.
We use similar html template to send it for different clients(Set -B), but '[Message clipped] View entire message' is NOT DISPLAYED in this mail ,even when the email is longer.
Tried minified HTML template , but still 'View entire message' is shown at bottom of gmail for only Set-A clients.
The HTML file size before copying to mail body for Set-A (40.11KB) is smaller than that of Set-B (49.09KB).
So I am assuming size is not the problem for this
I compared both the HMTL templates, no difference in styles or other HTML tags. Just the text content is different.
Kindly advise how to avoid this 'View Entire message' option being displayed.
For me it had to do with the character set of the email body. Email body "Hej på dig!" and "Content-Type: text/plain; charset=UTF-8" would reproduce the bug.
You need to make sure that the email body is indeed encoded as declared (check using "show original"). After converting the body from ISO-8859-1 to UTF-8 the problem went away.

Froala Editor - Converting image to base64 and sending email using nodemailer. For bigger images it is not working

we have a licensed version of froala. And we are trying to send the editor content as RTF mail.
Right now there is no option to get the content as RTF. Froala is giving it as HTML.
So we are using image.beforeUpload method and converting the image to base64 and sending the content to email.
For small size images it is converting and working fine. But If I convert a bigger image the base64 is very big, So the image is not showing in the email.
Can you provide any solution for the problem? How can I send images and videos embedded inside the froala editor to mail?
Is there any option to retrieve the content as RTF from froala itself.

Tabular format data in node js email

in my node js project, I am using gmail to send mail, mails are going fine, except that when I put data in tabular form with HTML code then rather printing the data in tabular form, it simply prints the html code.
what am I missing here, should I user any specific npm, as of now I am using nodemailer.
You might be writing the HTML code in the text field. Use nodemailer's html field
var mailOptions = {
html: '<b>Hello world!</b>',
}
and write your HTML code into this field.

base64 images not displaying in Outlook when using ejs + emailjs

I'm using a mix of ejs and emailjs to send out emails in my node.js app when various events happen. I'd like to embed a base64 image (a small logo) into the email when it sends, but both Outlook and Gmail (plus Inbox by Google) fail to render the image.
I'm using this bit of code to find the mime type of the image and put together the base64 string:
MyApp.prototype.ImageToBase64 = function(image) {
var mime = require("mime")
file = fs.readFileSync(__dirname + "/images/" + image, { encoding: 'base64'})
return 'data:' + mime.lookup(image) + ';base64,' + file;
}
That works great, because I'm able to copy and paste that resulting string right into my browser and see the image. But when I send the email via emailjs, Outlook converts the +s to +. When I "View Original" in Gmail, the base64 is split up into 'chunks'. Each chunk is on a newline and each line ends with a =. If I take Gmail's version and remove the = and newline then paste it into my browser, the whole picture loads perfectly, but it just refuses to load anywhere else, regardless of whether the user is in my contact list or not.
Here's the code I'm using to send the email:
// Host, username, password and SSL (false) all set above here
server.send({
text: myTemplate,
from: "me#example.com",
to: "someone#example.com",
subject: "Testing",
attachment: [
{data:myTemplate, alternative:true}
]
})
And the template looks like this (truncated, as the other bits aren't important):
<body>
<p><img src="<%- ImageToBase64("logo.png") %>"></p>
<h1><%= Name %> has been triggered</h1>
<p><%= Name %> has been triggered. It was triggered on <%= TheDate %></p>
Any hints?
EDIT: I tried setting the headers in the "attachment" property, but with no luck
Outlook uses Word to render the images, and Word does not support embedded (src="data:image") images.
You need to attach the image as a file and set the Content-ID MIME header to the value matching the cid attribute on the image (<img src="cid:xyz">) in the HTML body.
Okay, so even though this answer is from 2013, it seems like the wisdom still holds true, in that base64 image support sucks in email clients.
Basically the only mail clients that still support inline images are either older ones (e.g. Office 2007), or Apple / Android's default mail apps.
While that's a bit disappointing, it's not the end of the world, as the email will only be seen by people on the same network as my app, so I can just point to the image hosted on the web portion of the app.
But for anyone else trying this, host your image on an image sharing site like Imgur or on your own server and use a regular ol' <image> tag to display it.
So much for self-contained emails, right?

How to send iCal with PHPMailer

I am using the latest version of PHPMailer 5.2.7 and I would like to send an iCal event generated using the PHP class iCalcreator
I could not find any documentation on how how to send an iCal. Does anyone have an example?
Once you generated the syntactically correct iCal code you just add the new file as an attachment:
$mailer->addAttachment('/path/to/your/file/schedule.ics', 'alternativename.ics', 'base64', 'text/calendar');
You may provide an alternative name for the original file. If the ICS data is in a string-object you can use $mailer->AddStringAttachment(...).
You can create manually the iCal code and then attached to the email (as attachment or inline). All you need to do after that is assign your ical string to the mail->iCal variable. Ex.
include_once("phpMailer/PHPMailerAutoload.php");
$mail = new PHPMailer();
$mail->Body = $description; // Your HTML decsription
$mail->AltBody = $description; // For non HTML email client
$mail->Ical = $ical; //Your manually created ical code
I was able to send iCal event inside the email, as inline. Also sending files attachment and keep the ical inside the email.

Resources