Programmatically create an embedded file attachment - c#

When I use Microsoft Outlook, it allows me to place file attachments in the body of the email rather than just attach them to the message. Is there a way to replicate this behavior using an HTML formatted email in C#? I am sending an automated email out with lots of attachments and it would help keep everything organized for the end user. I found ways to embed an image file into the email but not how to put attachments in. I believe these are called "inline" or "embedded" attachments.

No, HTML will only let you have embedded images.
RTF actually inserts icons inside special placeholders in the RTF body.
The icon position is specified by the Position parameter when calling Attachments.Add.

Related

Display a saved .msg message as HTML or ASP.NET

I have a problem. I need a way to import a saved .msg file from Outlook and then display this as html.
Ideally I would have an ASP:FileUpload control that the user would upload the email. Then I would want to parse this as markup so the email can be displayed in the website. I just don't know how to go about pulling this email message in and passing it as a new MailMessage object.
If I could bring the data from the file upload in as a new MailMessage object I would imagine I could read the information from the file and display this.
There has to be a way to display the contents of a .msg with C#. I can't imagine there isn't. I would REALLY like to not use third party plug-ins or .dll files. I have a feeling C# has this functionality somehow built into it. (maybe include one of the references?)
Have you considered using a third-party library to load the MSG file, and then retrieve the content of the message? Aspose.Email can probably do that for you.

Can we Embed an Image to a Email without using HTML?

I want to send an e-mail consisting an image from my C# program. I can completely do that using the code samples at How to Send Mails from your GMAIL Account through VB.NET or C#. Windows Programming, with a Bit of Customization
But when I used another email service, they just remove the HTML tagged part including the image from the email! So does anyone know a method to embed the image without using HTML tags?
Thanks in advance.
perhaps you can send it as an attachment?
Can that be an option for you?
There isn't really any way to do that other than the old:
send as attachment
just paste the full (or shortened) link into your content body

Sending html file with images via email

How can i send html mail with images in c#? Can i just set direct link to image on my server(something like <img src="http://mysite.ru/img.png" /> ) or i need attache image and then use link to my attached file? Is there any examples or ready to use libraries? What about css files and scripts?
There are multiple methods of coding in-line images. We use VB.NET in house and this site is an excellent reference http://www.systemnetmail.com/default.aspx
If you directly embed the links into the email (pointing to an external server) you'll get blocked by most clients, but the user can turn them on.
They can be embedded in the usual manner of:
<img src="http://go.com/go.gif" />
If you need it to show up by default you'll need to embed the image as an attachment and link to that attachement inline.
See: http://www.systemnetmail.com/faq/2.6.aspx
For CSS it is common to use inline style and no referenced files the images on the other side should be just links and not send with the email. You just need to declare the mail content as html and you are ready to go. JavaScript is also available I use it fir some repositioning.
See http://en.wikipedia.org/wiki/MHTML:
MHTML, short for MIME HTML, is a web
page archive format used to combine
resources that are typically
represented by external links (such as
images, Flash animations, Java
applets, audio files) together with
HTML code into a single file. The
content of an MHTML file is encoded as
if it were an HTML e-mail message,
using the MIME type multipart/related.
The first part of the file is normally
encoded HTML; subsequent parts are
additional resources identified by
their original URLs and encoded in
base64. This format is sometimes
referred to as MHT, after the suffix
.mht given to such files by default
when created by Microsoft Word,
Internet Explorer, or Opera. MHTML is
a proposed standard, circulated in a
revised edition in 1999 as RFC 2557.
Learning more about MHTML may be the key to solving the problem.
probably the best option is to use some package like MvcMailer.
Mvc Mailer display the following characteristics:
MvcMailer sends emails using the MVC views as Email Body with no effort. Here's a quick list of features:
a) Use Razor/WebForms views
b) Use Master pages
c) Write Testable Code
d) Pass values to your view using ViewBag or ViewModel and
e) Generate Absolute URL using Url.Abs method and
f) create multi-part emails by just adding a view file,
g) scaffold your mailers. MvcMailer has a MailerBase class that extends ControllerBase class.
So, Mailers are just like your Controllers. As a result, you can use all the controller goodies without any learning curve, period. The end result is a professional looking HTML email body ready for your to send to your website users.
Visit the Project site for a comprehensive tutorial on MvcMailer. https://github.com/smsohan/MvcMailer/wiki/MvcMailer-Step-by-Step-Guide
On the step guid you will find how you can send emails using images.
brgds.
sebastian.

Show mail message in WebBrowser control

I'm trying to design a mailing system (.NET C#).
Messages are stored in database in two tables:
message(Message_id, Receiver, Sender, Subject, ...) //message's header
message_parts(Message_id, Content_id, Part_type, Content)
So, the content of message is divided into parts (html body, plain text body, sources for html, attachments)
I can't find a way how could i display the message in the WebBrowser control in case when I have html with embedded images. I will have html that references images by content id, i will have images encoded in base64. Now how can I link them and display?
The only ideea that comes to me is building an mht file and open it in the WebBrowser.
But besides that i can't figure out how to do this too, the last thing i want is to create files on the local system.
So, the questions are:
how can I display a message broken into parts as explained above?
how to build an mht file having these parts?
maybe it's not a WebBrowser I should use, but some UI control that does the work for me?
Thank you!
You could create the mht file and set the mimetype to multipart/mime.
Here is a webpage which has some code to create MHT (possibly relying on dlls you need to install separately): http://www.eggheadcafe.com/articles/20040527.asp
Perhaps this might be helpful too: http://msdn.microsoft.com/en-us/library/aa488379(EXCHG.65).aspx

Is it possible to render the exact same HTML as Outlook does when displaying HTML Body of .msg files?

We are displaying HTML body extracted from .MSG files exported from Outlook.
To display the HTML body, one needs to decompress RTF from PR_RTF_Compressed field and then decode the RTF to HTML (outlook actually encodes HTML to RTF when exporting MSG files). We are using RDO library to parse the msg files and extract the HTML body.
RDO produces some HTML that is not always the same as Outlook displays (text size sometimes does not match etc.)
Is anybody aware of an implementation of HTML body extraction that would most closely match the appearance of HTML displayed by Outlook or is this impossible?
more thoughts than an answer...
Are you displaying the extracted body in a browser such as IE?
I expect that the issue is that Outlook (2007) uses the Word rendering engine to display HTML while browsers use their own. So, I don't think you are likely to find an extraction implementation that will help.
Can you apply a stylesheet to your extracted body document, that will override most of the inconsistencies?

Categories

Resources