VSTO (Outlook) is forcing MSG attachments to be of olEmbeddeditem type, but olByValue needed - outlook

I need to send email with .msg file attached to Lotus Notes (Domino) by using VSTO (from Outlook Add-In). When this file is received in Lotus Notes, the email body from msg file is appended to the end of the main mail.
From this problem I am assuming that the issue is in attachment type.
I am trying to set the attachment type to by olByValue by adding attachment :
mail.Attachments.Add(msgFilePath, OlAttachmentType.olByValue, 0, displayName);
but whatever type I specify, it is still set to olEmbeddeditem.
Is there any way, how to force msg attachment to be olByValue?
Thank you for any suggestion or advise.
Have a nice day.
Note: For reference I have created email in Lotus-Notes too with msg attached, sent to Outlook and than forwarded back to Lotus-Notes and msg is attached not appended to the end.

There is not much you can do in the Outlook Object Model - it always tries to be "helpful" and converts MSG files to embedded message attachments. If using Redemption is an option (I am its author), it will not change the type:
SafeMailItem sItem = new SafeMailItem();
sItem.Item = mail;
sItem.Attachments.Add(msgFilePath);

Related

Outlook Add-in file reading from mail

I am working on a Outlook add-in. I am not able to use the method item.getAttachmentsAsync in my plugin code to load and read the content of files.
I am getting ERROR TypeError: item.getAttachmentsAsync is not a function in run time.
var item = Office.context.mailbox.item;
var options = {asyncContext: {currentItem: item}};
item.getAttachmentsAsync(options, this.callback);
My requirement is explained below,
In the plugin we have a form and few fields are populated from mail body.
And I need mail attachments to auto upload to Form.
Please suggest a better way to do that.
using getAttachmentContentAsync I am able to get the file as a blob. but the problem is we need to call this method as soon after the mail opening. otherwise getting cors error

Outlook 365 get Mail Item

I have following problem:
We have an Outlook Addin (VSTO), with which we archive emails (orders) in SAP.
Now the plugin should be implemented for Outlook 365. I already looked at the new api and i get die subject or maitext but there seems no way to get to the raw .msg file.
So my question now is, is there a way to get an mailitem as an .msg file (or any other format)?
There are two ways may be you can try
Use the process to run the .msg
string file= #"C:\PWS\myMail.msg";
Process.Run(file);
Use OpenSharedItem to open it:
var app = new Outlook.Application();
var item = app.Session.OpenSharedItem(msgfile) as Outlook.MailItem;
//Do stuff with the mail.
item.Close(OlInspectorClose.olDiscard);
app.Quit();
Marshal.ReleaseComObject(item);

Outlook OLE Automation: BodyFormat not supported?

I am trying to send an email in Outlook using OLE Automation. At the moment, I am using VBS for testing purposes. When it works, I will switch to another language that supports OLE/COM.
The problem with my code is, that I get error 800a0005 "Invalid procedure call" with argument 'BodyFormat'.
According to the documentation of Microsoft, BodyFormat is existing since Outlook 2003. I am testing with Outlook 2010.
My code:
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
With newMail
.BodyFormat = olFormatHTML
.HTMLBody = "<HTML><H2>The body of this message will appear in HTML.</H2><BODY>Type the message text here. </BODY></HTML>"
.Display
End With
The background: At the moment, some customers receive emails in TNEF format and can't open the email attachment winmail.dat. So I am trying to force Outlook to use HTML instead of RichText.
What can I do?
Constant olFormatHTML is not defined by default.
Add the following line at the beginning of your VBS code:
Const olFormatHTML = 2

How to send an email with multiple attachments from Gmail using API client library for .NET

My app uses Google API client library for .NET to send emails with attachments.
When using Send(), I'm facing some limitations when it comes to file size of the attachments. So, I guess switching to Resumable upload as upload method may help. But it's pretty much undocumented.
Looking into source code, I guess using different Send() overload may be the way forward, but I can't figure out how to use it properly.
So, instead of attaching the files into message and calling it like this:
var gmailResult = gmail.Users.Messages.Send(new Message
{
Raw = base64UrlEncodedMessage
}, "me").Execute();
I should not attach the files to message and do something like following?
var gmailResult = gmail.Users.Messages.Send(new Message
{
Raw = base64UrlEncodedMessage
}, "me", fileStream, contentType).Upload();
The second version does not return any API error, but does nothing. I'm obviously missing something here.
How do I attach more than one attachment?
This is kind of an old question, but putting an answer here just in case anyone else needs it:
I was able to achieve this by converting my mime message into a stream (attachment(s) included), and then calling this overload on Send:
UsersResource.MessagesResource.SendMediaUpload googleSendRequest = service.Users.Messages.Send(null, "youremail#gmail.com", mimeMessageStream, "message/rfc822");
IUploadProgress created = googleSendRequest.Upload();
This will upload all of the attachments with the email message content and then send it off. I was able to send two 5 megabyte attachments in an email. Previously I was not able to send even one of those via the other Send method that takes in a base64 encoded mime message.

Send email attachment to a local folder

I am trying to send an email from a client PC (i.e. Windows) with an attachment and have the attachment saved to a local folder on the same client PC. I have looked at a couple of alternatives, such as MailDrop (email to dropbox) and Outlook 2003 Interop library - but want to make sure I am implementing this the best way.
Does anyone have any different ideas on a simple/elegant solution?
As long as you know Outlook will be installed on all the clients the Outlook solution works very well. You can create a file and save it, then in your outlook interop you just attach and send. You didn't specify what tools you are using but here's the basic email creation method I use for Outlook in C# (Where OutlookSetup.OutlookApp is just a static method that returns the currently open instance of the Outlook application or creates a new one if Outlook isn't open). Otherwise there are several examples here on SO of using SmtpClient to achieve similar ends.
public EmailMessage(EmailInfo emailInfo, string filenameToAttach=null)
{
Message = OutlookSetup.OutlookApp.CreateItem(OL.OlItemType.olMailItem);
Message.To = emailInfo.To;
Message.CC = emailInfo.Cc ?? "";
Message.Subject = emailInfo.Subject;
if (filenameToAttach != null)
{
Message.Attachments.Add(filenameToAttach);
}
}

Resources