tags:

views:

339

answers:

2

Hello there,

I have a requirement to send emails containing both text and Images.
So, I have .mhtml file that contains the content that needs to be emailed over.

I was using Chilkat for this, but in outlook 2007 it is showing the mhtml file as different attachments(html+images).

Can anyone suggest me some other component for sending mhtml emails.
FYI, I am using .Net 3.5

Also, I do not want to save the images on server before sending them.

Thank you!

+1  A: 

I use plain old native MailMessage class. This previous answer can point you in right direction

EDIT: I built a similiar code some time ago, which captures an external HTML page, parse it's content, grab all external content (css, images, etc) and to send that through email, without saving anything on disk.

Rubens Farias
Thanks for your reply. But the post at above link is using LinkedResource which needs all images to be saved physically on server, which I do not want :-(
inutan
That isn't entirely true: LinkedResource first argument is a stream, so your image can be stored at some database, for instance
Rubens Farias
A: 

Here is an example using an image as an embedded resource.

MailMessage message = new MailMessage();
message.From = new MailAddress(fromEmailAddress);
message.To.Add(toEmailAddress);
message.Subject = "Test Email";
message.Body = "body text\nblah\nblah";

string html = "<body><h1>html email</h1><img src=\"cid:Pic1\" /><hr />" + message.Body.Replace(Environment.NewLine, "<br />") + "</body>";
AlternateView alternate = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);
message.AlternateViews.Add(alternate);

Assembly assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream("SendEmailWithEmbeddedImage.myimage.gif")) {
    LinkedResource picture = new LinkedResource(stream, MediaTypeNames.Image.Gif);

    picture.ContentId = "pic1"; // a unique ID 
    alternate.LinkedResources.Add(picture);

    SmtpClient s = new SmtpClient();
    s.Host = emailHost;
    s.Port = emailPort;
    s.Credentials = new NetworkCredential(emailUser, emailPassword);
    s.UseDefaultCredentials = false;

    s.Send(message);
}
}
Tom Brothers
As I am getting mhtml output from Aspose utility, I don't have control over Images' names so setting ContentId is not feasible in my case, which I suppose is the basis of using LinkedResource. Any other ideas?
inutan