Mime - Where can I find where images in emails are stored? - c#

I'm currently sending reply emails via SMTP using SendGrid to emails I receive. I save the emails I get as .msg and load them as MimeMessage. I add some text as a reply but if the emails have images, the images don't seem to get passed through and I'm not sure exactly where they are. My goal is to send the reply emails with images being retained as currently they show as blank boxes in Outlook saying 'The linked image cannot be displayed. The file may have been moved, renamed, or deleted'.
From my research, I am seeing that images are passed in through attachments and the body of the email show the image as cid:image001.png... . I can't find where the actual images are stored though. When I look into the MimeMessage, attachment is null (unless I attach a file to the email, that file will show but not images within a body of email)
Does anyone have any tips for where to look for the image(s) of emails?
Update: I found the image stored in Body Parts. Will figure out how to pass that one to the reply next.

Related

Is it Possible to Reply From an .EML file?

I would like to know if it is possible to open and reply as a response message on top of a saved .eml file using C#?
If yes, are there any guides that I can follow?
I am able to do so with EWS EmailMessage where the message resides in Inbox. However, due to requirements, I am required to retrieve and reply from a saved .eml file instead of replying from the email in Inbox directly.
Thank you.
No you can't do this using the EWS reply operations because EWS is a Server side API while using the EWS Managed API you using Client side library that just instrumenting the SOAP call to the backend whenever an action is taken. You can temporary import the EML back in the server https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-import-items-by-using-ews-in-exchange and then you reply and then delete the Message again if don't want it to exist. If your want to send using EWS you didn't want to import the message use something like mimekit to generate the MIME of the response message offline http://www.mimekit.net/docs/html/Frequently-Asked-Questions.htm then you can just sent the Mime generated by mimekit via EWS.
In theory you could achieve this, by first opening the EML file (please see this question and answer):
Retrieve Email Information from .EML Files
And then when you have the contents of the message in code, copy the data over to whatever email-sending API you are using.
Step 1:-
Click the message options menu in the top right corner of the message. Select Save email.
Step 2:-
Save the file. The file name will default to the subject line of the email, with special characters removed. Your download options depend on whether you're using Front on the web or in the desktop app:
*Web: Your file automatically saves to wherever you have it set up in your browser settings (like your Downloads folder)
*Desktop app: You will get the “Save As” prompt where you can rename the file and choose your download location
Step 3:-
You will see your .eml file in your chosen location. You can attach it to a message via drag-and-drop or with the attachment file picker.

create email with embedded image gmail api

I am able to create an email draft using the gmail api. I'm also able to create a draft with an embedded image if the image is a real file.
The next step I want to reach is to create a draft with an embedded image where the image is just a screenshot on my clipboard. By creating the draft my html img tag looks something like
" img width="593" height="363" src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwM......"
but in gmail this part of my draft is empty.
Does someone know any solutions for this ?
Thanks a lot !

Is it possible to send an attachment in Outlook as a URL

I have an Outlook addin that handles attachments by sending them to our server and then embedding a link into the body of the email containing the URL to the uploaded attachment.
This works but it is not 100% satisfactory because the URLs can get broken depending in the email client and the sender will not see their attachments listed at the top of there email where they are use to seeing them.
Ideally what I would like to do is exactly what is being done for OneDrive.
Currently if I add an attachment and provide a URL as the source it will download the file and send it as a normal attachment which is the exact opposite of what I want. I have noticed that if it fails to download the file it will then just send the URL as an attachment which is what I want. But sending broken URLs is not very useful.
Using
Outlook.MailItem.Attachments.Add("https://myserver.com/somefile", 7, 1, "MyAttachment")
If I set the attachment type to '7' which is what is used for OneDrive attachments I can get it to send the URL but it will first complain about not being able to set some access rights and if the sender clicks OK to continue anyway the attachment will appear to the sender and the receiver as residing on OneDrive which it is not, but clicking the URL will download the file from my server as I want.
My question is: Is it possible to send a none OneDrive URL as an attachment?
(I expect the answer is no, but I am hoping some Outlook guru out there may know some trick to do this.)
My other alternative it to wrap my URLs in an small html file that is then sent as a normal attachment and when opened will provide the link to the actual file.

attachments with ics file in c#

I am trying to send an ICS (calendar) file to someone that read it using Office365, using C#.
Sending just the ICS works fine. But I have to attach a file.
At this point, the mail is received without calendar, or the calendar is attached to the email and cannot be used, or the attachment is missing.
I tried 2 different ways:
1. send attachment inside VEVENT, using ATTACH;ENCODING=BASE64;VALUE=BINARY;X-FILENAME=file.txt:, but this does not show any attachment in Office365 (like here: Attaching a file to an iCalendar)
2. send attachment as a separate file, and attach it to VEVENT using ATTACH:CID:, but this time the calendar file is displayed as attachment
The second way should work if I can format the mail message to look like this:
multipart/mixed
multipart/alternative
text/plain
text/calendar;method=REQUEST
text/calendar (with a content-disposition:attachment)
(as described in Multipart email with text and calendar: Outlook doesn't recognize ics)
If I send a calendar invite using Outlook365, the message looks like that.(but instead of the calendar as attachment, the image or doc is attached)
but using System.Net.Mail.MailMessage, I can generate a message like this
multipart/mixed
multipart/alternative
text/plain
text/calendar;method=REQUEST
multipart/mixed
text/plain (with a content-disposition:attachment)
Desktop version of Outlook 2007 shows both calendar and attachment, so it seems that Outlook365 is very strict about the format.
But how can I send, using .NET classes, an email that does not have the extra multipart/mixed section? MailMessage class generate for the Attachments collection a new section with content type multipart/mixed, insead of adding them to the top level.

sending email with images

I have a WinForms application where a user can configure email templates that will later get mail merged with client data from the database and then sent via SMTP.
I have everything working fine, but the issue comes when the user saves images inside the template body. I'm using a DevExpress RichEdit control to allow the users to create this email body, and that control converts it to HTML that I use to send. When images are there, it uses data-uri to embed the image directly into the HTML.
The problem now comes when I send the email in this way using data-uri images, not all clients render it properly. I just tested it in Outlook, and it doesn't seem to work. I know some web based email clients will work, but I need this to work all the time, at least for the widely used email clients.
I'm wondering if others have solved this problem and what might be the best solution here? I suppose I could send the images as attachments and then reference the attachment, although I'm not sure if this is a best practice. The other alternative though is to host each image on a server somewhere, then create a service which would have to store the images (like in a DB), and provide a way to query this image over the web using an ID. Then my emails would use an img src=site/getImg?imgID=xxx type thing. However, this seems like a lot of work to do what I want to accomplish and I'm hoping I could avoid it with something easier.
Thanks in advance for any advice!!
Adding images as attachments will work, but has the downside of a larger payload and higher bandwidth utilization both for you and for your recipients. The code for adding attachments in .net is pretty simple:
var message = new MailMessage();
foreach (string path in attachmentPaths)
{
if (File.Exists(path))
{
message.Attachments.Add(new Attachment(path));
}
}
On the other hand, referencing images stored on the web somewhere reduces the size of your emails and also opens up the possibility of gathering tracking data on clients that request images. Of course, most email clients will first ask the user whether they want to download images, so your tracking will only be rough.
you should be try save the images in the local disk , and the next include the who Embedded images.
// Add image attachment from local disk
Attachment oAttachment = oMail.AddAttachment( "d:\\test.gif" );
// Specifies the attachment as an embedded image
// contentid can be any string.
string contentID = "test001#host";
oAttachment.ContentID = contentID;
oMail.HtmlBody = "<html><body>this is a <img src=\"cid:"
+ contentID + "\"> embedded image.</body></html>";
Sorry for not explain, I speak only a little in english

Categories