Outlook add-in disable automatic compression of JPEG attachment - c#

I am writing an Outlook add-in to be able to insert automatically an image into an email using CID.
However, everytime I add an image as attachment (jpeg), the image is compressed automatically by Outlook and I have a big lost of quality.
Is it possible to avoid compression of images for attachment?
Here is the code that I am using so far:
var attachment = mailItem.Attachments.Add( #"D:\\image.jpg" , Outlook.OlAttachmentType.olEmbeddeditem , null , "Some image display name" );
string imageCid = "image.jpg#123";
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F", "image/jpeg"); // PR_ATTACH_MIME_TAG
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", imageCid); // PR_ATTACH_CONTENT_ID
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B", true); // Hide attachment in the email
mailItem.HTMLBody = String.Format( "<body><img src=\"cid:{0}\" width='450' height='150' alt=''></body>" , imageCid);
Thanks a lot for any help

Not much you can do if the message is then displayed by Outlook. You can try to add the image immediately prior to it being sent (Aplication.ItemSend event).

Related

Mimekit how to embed svg without attach them

I have this little piece of code
var builder = new BodyBuilder();
var image = builder.LinkedResources.Add(logoPath);
image.ContentId = MimeUtils.GenerateMessageId();
textMsg = textMsg.Replace("{logo}", image.ContentId);
builder.HtmlBody = textMsg;
msg.Body = builder.ToMessageBody();
It works perfectly except that if I use a .png image it isn't attach to the mail but if it is an .svg it is attach. I tried to convert the svg to base64 but it didn't work.
As I show in the images below, if it is a .svg the image is attach at the top of the mail but if it is a.png it doesn't. Is it possible to do the same with .svg? I don't want the attached file.
The issue you are facing is a limitation of the receiving mail client, not anything you are doing wrong with the images in your email message.
The client you are using to receive the message does not support SVG and so has decided that whenever it encounters an SVG image, it will offer it to the user as an attachment.

C# - Copy pasting of image into outlook set it as twice attachment files

I am currently working on an addin project for outlook in visual studio 2013.
When I copy paste an image into outlook and send mail through it,it considers the same image twice in the html attachment.How can I allow to show only one image in the attachment? Or how can remove the second attachment?
Copy Pasted one Image to outlook:
Outlool.MailItem.Attachments look like:
Got two Attachments when I pasted one Image.
Please help. Thanks
Instead, can you try to get a picture from the local? Just test the problem and see if there will be such a problem.
Also, I found a way to add attachments from locally saved files to the mail and display them in HTML to the body. For your reference:
newMail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
Outlook.Attachment attachment = newMail.Attachments.Add(#"path.imageformat", Outlook.OlAttachmentType.olEmbeddeditem, null, $"someTitle");
string imagecid = "whatever";
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3613041E", imagecid);
newMail.HTMLBody = String.Format("", imageCid);

c# open pop - save e-mail (HTML with inline attachements) to database

Found a problem with saving e-mail to database(as byte[] - already tried with various methods:
saving "RawMessage",
executing Message.
Load via "MemoryStream" etc..),
retrieving it and re sending.
When I send this saved e-mail, recipient does not see inline attached image (in place where image should be is information that picture was not found or couldn't be loaded).
My actual code version:
byte[] toDB = message.RawMessage; // then it goes to DB
//later in code
OpenPop.Mime.Message raw = new OpenPop.Mime.Message(fromDB, true);
//then I fill in new Message object with new values, only body remains the same:
mailMessage.Body = System.Text.Encoding.Default.GetString(raw.FindFirstHtmlVersion().Body);
Thanks :)

UIImageView.Image to mail attachment with MonoTouch

I am new to MonoTouch and I am trying to send an email with an image as attachment that a user will tame from camera or pick from gallery.
I have created the program and it runs correctly (I have an imageview controller which loads an image from uiimagepicker to imageview. Then I call MFMailComposeViewController but I don't know how to pass the image from imageview to addAttachmentdata method.
I suppose first I have to save the image from imageview as a file but I don't know how to do it and I can't find documentation for it.
First you need to turn the UIImage into an NSData, e.g. using AsPNG or AsJPG, then use the right MIME type for the image. Here's an example:
MFMailComposeViewController email = new MFMailComposeViewController ();
// any UIImage will do
UIImage img = UIImage.FromFile (".../anyimage.png");
email.AddAttachmentData (img.AsPNG (), "image/png", "image.png");
email.SetSubject ("Photo from my iPhone");
email.SetMessageBody ("Here's the attachment!", false);
controller.PresentModalViewController (email, false);
Note: the "image.png" is a suggested file name given to the recipient email software (i.e. it's not a local file in your device and does not need to match anything that exists).

Using an HTTP handler in ASP.NET to generate an image for display in email

I'm generating a barcode image as the response from an HTTP handler, like so:
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
context.Response.ContentType = "image/Jpeg";
MemoryStream ms = new MemoryStream();
Bitmap objBitmap = GenerateBarcode(context.Request.Params["Code"]);
objBitmap.Save(ms, ImageFormat.Jpeg);
context.Response.BinaryWrite(ms.GetBuffer());
}
I go to http://www.MyWebsite.com/MyProject/BarCode.aspx?code=12345678 and it works great. Likewise I stick <img alt="" src="http://www.MyWebsite.com/MyProject/BarCode.aspx?code=12345678"> on my webpage and it works great. But I stick that same image tag in an HTML email and it doesn't show up (at least not in MS Outlook 2007; I haven't tested other email clients yet.)
I'm guessing this is somehow related to the fact that I'm using an HTTP handler, as other, static images in the email are showing up fine. How can I fix this so that the image shows up? (I can't just use a static image because the code is determined at the time the email is sent.)
Update:
It turns out I hadn't noticed a key detail. The image isn't just not showing up; rather the image src attribute is getting replaced with "http://portal.mxlogic.com/images/transparent.gif". I've determined that using the .aspx or .ashx extensions triggers this replacement (or probably any extension except those expected for images like .gif or .jpg), and that including a query string in the URL also triggers this, even when it's a standard image extension. I guess it's some overzealous security feature. So including an image like BarCode.aspx?code=12345678 just isn't going to work.
It occurs to me that I could do something like <img alt="" src="http://www.MyWebsite.com/MyProject/12345678/BarCode.jpg"> and then create a handler for all files named BarCode.jpg. Here 12345678/ isn't an actual path but it wouldn't matter since I'm redirecting the request to a handler, and I could scrape the code value from that phony path in the URL. But, I'd probably have to change some IIS setting to have requests for .jpg files handled by ASP.NET, and I'd want to still make sure that other JPEGs besides my BarCode.jpg loaded normally.
Honestly, I'm not sure if it's worth the hassle.
Microsoft Office Outlook 2007 uses the HTML parsing and rendering engine from Microsoft Office Word 2007 to display HTML message bodies. more
which leaves us with some hairy points
The limitations imposed by Word 2007 are described in detail linked off in the article, but here are a few highlights:
no support for background images
(HTML or CSS)
no support for forms
no support for Flash, or other
plugins
no support for CSS floats
no support for replacing bullets with
images in unordered lists
no support for CSS positioning
no support for
animated GIFs
i think your best bet would be to embed the image using the LinkedResource class, something like
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("...");
mail.To.Add("...");
//set the content
mail.Subject = "Test mail";
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image." ", null, "text/html");
//create the LinkedResource (embedded image)
LinkedResource logo = new LinkedResource(GenerateBarcode(Code)));
logo.ContentId = "logo";
htmlView.LinkedResources.Add(logo);
mail.AlternateViews.Add(htmlView);
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
I don't know why it doesn't work but if you are saying that static images from the site hosting the handler work fine here's a slightly modified version you might try:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
using (var image = GenerateBarcode(context.Request.Params["Code"]))
{
image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
}
}
No need to clear the response in a generic handler as there's nothing written yet
Content-Type is image/jpeg
No need of intermediary memory stream, you could write directly to the response
Make sure to properly dispose the bitmap
You will have to put the image as an attachment, or use html in the mail. Probably your error happends due to Outlook though.
This link suggests the problem, as you suggested is a security/anti-SPAM feature causing the problem (mxlogic.com points to a McAfee product)

Categories

Resources