I m getting error when i m trying to send email to different Recipients with their respective attachment. i m using looping to change the Recipients and attachment but getting error. pls help to resolve this issue
my code is
private void BtnEmail_Click(object sender, EventArgs e)
{
try
{
string[] fileEntries = System.IO.Directory.GetFiles(txtPdfFiles.Text, "*.pdf");
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
if (RtxtBox.Text == "")
{
MessageBox.Show("Please set Mail body text");
GrpMailBody.Visible = true;
}
else
{
oMsg.HTMLBody = RtxtBox.Text;
}
if (RtxtSubject.Text == "")
{
MessageBox.Show("Please Enter Mail Subject");
GrpMailBody.Visible = true;
}
else
{
oMsg.Subject = RtxtSubject.Text;
}
String sDisplayName = "MyAttachment";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
for (int i = 0; i <= grvExcelData.RowCount; i++)
{
string EmaildID = grvExcelData.Rows[i].Cells[3].Value.ToString();
string sFileName = grvExcelData.Rows[i].Cells[5].Value.ToString()+".pdf";
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(EmaildID);
foreach (string fileName in fileEntries)
{
string fileN = "";
string xfileName;
xfileName=System.IO.Path.GetFileName(fileName);
if (xfileName == sFileName)
{
Outlook.Attachment oAttach = oMsg.Attachments.Add(#fileName, iAttachType, iPosition, sDisplayName); //getting error in this line
}
else
{
}
}
oRecip.Resolve();
oMsg.Send();
oRecip = null;
//oRecips = null;
oMsg = null;
oApp = null;
}
Add this--
Add reference Microsoft.Office.Interop.Outlook
using Outlook = Microsoft.Office.Interop.Outlook;
public void sendEMailThroughOUTLOOK()
{
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody = "Hello!!";
//Add an attachment.
String sDisplayName = "MyAttachment";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
//now attached the file
Outlook.Attachment oAttach = oMsg.Attachments.Add(#"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName);
//Subject line
oMsg.Subject = "Your Subject will go here.";
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("EmailAddress");
oRecip.Resolve();
// Send.
oMsg.Send();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
}//end of try block
catch (Exception ex)
{
}//end of catch
}//end of Email Method
Try to add Outlook Inspector as described here:
https://groups.google.com/forum/#!msg/microsoft.public.outlook.program_vba/lLJwbwwl-XU/gRuQYRpJtxEJ
using Outlook = Microsoft.Office.Interop.Outlook;
try
{
string[] fileEntries = System.IO.Directory.GetFiles(txtPdfFiles.Text, "*.pdf");
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector oInspector = oMsg.GetInspector;
// ...
}
Related
I have a custom add-in which gets the body on clicking a button when it got installed. so I am getting this error on a customer machine. code is working fine on my side and for other customers but one customer is facing this problem.
this is my code
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Microsoft.Office.Interop.Outlook.Application olApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace ns = olApp.GetNamespace("MAPI");
Explorer olExp = olApp.ActiveExplorer();
Selection olSel = olExp.Selection;
string msg = "";
int iterate = 1;
MAPIFolder inbox = null;
if (olSel.Count > 1)
{
MessageBox.Show("Sorry! You can't report more then 1 email at a time", "Report Email");
return;
}
foreach (_MailItem mail in olSel)
{
inbox = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
mail.GetInspector.Display(false);
Thread.Sleep(2100);
string screenShot = getScreenShot(mail);
mail.GetInspector.Close(OlInspectorClose.olDiscard);
String msgToShow = "Are you sure you want to report this email as suspicious?";
if (mail != null && mail.Subject != null)
msgToShow += "\n\nSubject : " + mail.Subject.ToString();
DialogResult dr = MessageBox.Show(msgToShow, "Please Confirm", MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation);
if (dr == DialogResult.Yes)
{
msg += reportMail(mail, screenShot, e);
}
else {
return;
}
iterate++;
break;
}
if (!msg.Equals(""))
MessageBox.Show(msg, "Report Email");
else
return;
if (!msg.Contains("Success"))
return;
MailItem moveMail = null;
MAPIFolder subfolder = null;
try
{
subfolder = inbox.Folders["Reported Emails"];
}
catch (System.Exception ex) {
subfolder = inbox.Folders.Add("Reported Emails", OlDefaultFolders.olFolderInbox);
}
foreach (MailItem eMail in olSel)
{
try
{
moveMail = eMail;
if (moveMail != null)
{
string titleSubject = (string)moveMail.Subject;
moveMail.Move(subfolder);
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private string reportMail(_MailItem mail, string screenShot, RibbonControlEventArgs e)
{
try
{
var m = Globals.ThisAddIn.Application.GetNamespace("MAPI");
var mailitem = mail;
if (mailitem != null)
{
// Console.WriteLine("Email body ::: " + mailitem.HTMLBody);
String reporterEmail = getReporterEmail(mailitem);
String senderEmailAddress = "";
String senderName = "";
AddressEntry mailsender;
if (reporterEmail.Equals(""))
{
MessageBox.Show("Sorry! This email can't be reported because you are not included in Recipients.", "Report Email");
}
else
{
if (mailitem.SenderEmailType == "EX")
{
mailsender = mailitem.Sender;
if (mailsender != null)
{
if (mailsender.AddressEntryUserType == OlAddressEntryUserType.olExchangeUserAddressEntry || mailsender.AddressEntryUserType == OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
{
ExchangeUser exchUser = mailsender.GetExchangeUser();
if (exchUser != null)
{
senderEmailAddress = exchUser.PrimarySmtpAddress;
senderName = exchUser.Name;
}
}
}
}
else
{
senderEmailAddress = mailitem.SenderEmailAddress;
senderName = mailitem.SenderName;
}
String emailHeader = mailitem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");
String emailBody = mailitem.Body.Replace("%"," percent").Replace("#","").Replace("|", "");
//String res = HttpPost(Properties.Settings.Default.address, "ReporterEmail=" + reporterEmail + "&suspectedName=" + senderName + "&FromEmail=" + senderEmailAddress
// + "&ToEmail=" + mailitem.To + "&Subject=" + mailitem.Subject + "&EmailBody=" + emailBody + "&AttachmentName=" + GetAttachments(mailitem)
// + "&reporter=" + reporterEmail + "&emailHeader=" + emailHeader + "&mailImage=" + screenShot);
String htmlBody = mail.HTMLBody;
MessageBox.Show(htmlBody);
Dictionary<string, object> postParameters = new Dictionary<string, object>();
postParameters.Add("ReporterEmail", reporterEmail);
postParameters.Add("suspectedName", senderName);
postParameters.Add("FromEmail", senderEmailAddress);
postParameters.Add("ToEmail", mailitem.To);
postParameters.Add("Subject", mailitem.Subject);
postParameters.Add("EmailBody", emailBody);
List<String> attachmentDetails = GetAttachments(mailitem);
postParameters.Add("AttachmentName", attachmentDetails[0]);
postParameters.Add("reporter", reporterEmail);
postParameters.Add("emailHeader", emailHeader);
postParameters.Add("mailImage", screenShot);
string res = HttpPost(Properties.Settings.Default.serverAddress+ "/PhishRod-portlet/reporter", postParameters, htmlBody,attachmentDetails[1]);
return res + "\n";
}
}
}
catch (System.Exception ex)
{
log.Error(ex);
return "Error: " + ex + "-- - " + ex.StackTrace.ToString() + "\n";
}
return "";
}
In the event handler of your button I see the following lines of code:
Microsoft.Office.Interop.Outlook.Application olApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace ns = olApp.GetNamespace("MAPI");
There is no need to create a new Outlook Application instance in the add-in. Instead, you need to use the Application property which doesn't trigger a security issue when dealing with OOM from external applications:
var app = Globals.ThisAddIn.Application
Here is the problem:
use Attachment.SaveAsFile() to save contact's picture on disk.(successfully)
change the contact's picture in outlook manually.
repeat step 1, but i get the old picture, not the new one in step 2.
EDIT:
I have know how to save contact's picture on disk.
The problem is that the picture which i get is not the newest one.
Here is the code:
//[Outlook] is short for [Microsoft.Office.Interop.Outlook]
Outlook.Application outlook = new Outlook.Application();
Outlook.MAPIFolder folder = outlook.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
foreach (var item in folder.Items) {
if (item is Outlook.ContactItem) {
Outlook.ContactItem contact = null;
Outlook.Attachments atts = null;
Outlook.Attachment att = null;
string path = "";
contact = item as Outlook.ContactItem;
if (!contact.HasPicture) { continue; }
path = #"C:\Temp\" + contact.EntryID + ".jpg";
atts = contact.Attachments;
att = atts["ContactPicture.jpg"];
if(File.Exists(path)){
File.Delete(path);
}
att.SaveAsFile(#"C:\Temp\" + contact.EntryID + ".jpg");
Marshal.ReleaseComObject(att);
att = null;
Marshal.ReleaseComObject(atts);
atts = null;
Marshal.ReleaseComObject(contact);
contact = null;
}
}
thanks!
I find the resolution on Contact picture retrieved via PIA doesn't change when updated in Outlook
I didn't release the folder.Items
Here is the modified codeļ¼
//[Outlook] is short for [Microsoft.Office.Interop.Outlook]
Outlook.Application outlook = new Outlook.Application();
Outlook.MAPIFolder folder = outlook.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items items = null;
items = folder.Items;
foreach (var item in items) {
if (item is Outlook.ContactItem) {
Outlook.ContactItem contact = null;
Outlook.Attachments atts = null;
Outlook.Attachment att = null;
string path = "";
contact = item as Outlook.ContactItem;
if (!contact.HasPicture) { continue; }
path = #"C:\Temp\" + contact.EntryID + ".jpg";
atts = contact.Attachments;
att = atts["ContactPicture.jpg"];
if (File.Exists(path)) {
File.Delete(path);
}
att.SaveAsFile(#"C:\Temp\" + contact.EntryID + ".jpg");
Marshal.ReleaseComObject(att);
att = null;
Marshal.ReleaseComObject(atts);
atts = null;
Marshal.ReleaseComObject(contact);
contact = null;
}
}
if (items != null) {
Marshal.ReleaseComObject(items);
items = null;
}
EDIT:
Problem happened with above code. Sometimes it got the old picture.
I added GC.Collect(); at the end,then it worked well.
So i tried the following code. But the problem remained.
//[Outlook] is short for [Microsoft.Office.Interop.Outlook]
Outlook.Application outlook = new Outlook.Application();
Outlook.MAPIFolder folder = outlook.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items items = folder.Items;
foreach (var item in items) {
if (item is Outlook.ContactItem) {
Outlook.ContactItem contact = item as Outlook.ContactItem;
string path = "";
Outlook.Attachment att = null;
if (!contact.HasPicture) { continue; }
path = #"C:\Temp\" + contact.EntryID + ".jpg";
att = contact.Attachments["ContactPicture.jpg"];
if (File.Exists(path)) {
File.Delete(path);
}
att.SaveAsFile(#"C:\Temp\" + contact.EntryID + ".jpg");
}
}
GC.Collect();
Finally i use the following code. Release all com objects,then call GC.Collect().
//[Outlook] is short for [Microsoft.Office.Interop.Outlook]
Outlook.Application outlook = new Outlook.Application();
Outlook.MAPIFolder folder = outlook.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items items = folder.Items;
foreach (var item in items) {
if (item is Outlook.ContactItem) {
Outlook.ContactItem contact = null;
Outlook.Attachments atts = null;
Outlook.Attachment att = null;
string path = "";
contact = item as Outlook.ContactItem;
if (!contact.HasPicture) { continue; }
path = #"C:\Temp\" + contact.EntryID + ".jpg";
atts = contact.Attachments;
att = atts["ContactPicture.jpg"];
if (File.Exists(path)) {
File.Delete(path);
}
att.SaveAsFile(#"C:\Temp\" + contact.EntryID + ".jpg");
Marshal.ReleaseComObject(att);
att = null;
Marshal.ReleaseComObject(atts);
atts = null;
Marshal.ReleaseComObject(contact);
contact = null;
}
}
if (items != null) {
Marshal.ReleaseComObject(items);
items = null;
}
Marshal.ReleaseComObject(folder);
folder = null;
Marshal.ReleaseComObject(outlook);
outlook = null;
GC.Collect();
I have the following code:
string imageSrc = "C:\\Documents and Settings\\menonsu\\Desktop\\screenScrapper\\Bitmap1.bmp";
oMsg.HTMLBody = "<HTML><BODY><img src = \" cid:Bitmap1.bmp#embed \"/><br><font size=\"2\" face=\"Courier New\">" + introText + "</font>" + body + "<font size=\"2\" face=\"Courier New\">" + conclText + "</font>" + " </BODY></HTML>";
Microsoft.Office.Interop.Outlook.Attachment attc = oMsg.Attachments.Add(imageSrc, Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem, null, "");
attc.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "Bitmap1.bmp#EMBED");
//Send the message.
oMsg.Save();
For some reason the email is just showing an x when i try to run this code...anyone know why?
The following is working code with two ways of achieving this:
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
Method1();
Method2();
}
public static void Method1()
{
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mailItem.Subject = "This is the subject";
mailItem.To = "john#example.com";
string imageSrc = "D:\\Temp\\test.jpg"; // Change path as needed
var attachments = mailItem.Attachments;
var attachment = attachments.Add(imageSrc);
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F", "image/jpeg");
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "myident"); // Image identifier found in the HTML code right after cid. Can be anything.
mailItem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/id/{00062008-0000-0000-C000-000000000046}/8514000B", true);
// Set body format to HTML
mailItem.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
string msgHTMLBody = "<html><head></head><body>Hello,<br><br>This is a working example of embedding an image unsing C#:<br><br><img align=\"baseline\" border=\"1\" hspace=\"0\" src=\"cid:myident\" width=\"\" 600=\"\" hold=\" /> \"></img><br><br>Regards,<br>Tarik Hoshan</body></html>";
mailItem.HTMLBody = msgHTMLBody;
mailItem.Send();
}
public static void Method2()
{
// Create the Outlook application.
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
//Add an attachment.
String attachmentDisplayName = "MyAttachment";
// Attach the file to be embedded
string imageSrc = "D:\\Temp\\test.jpg"; // Change path as needed
Outlook.Attachment oAttach = mailItem.Attachments.Add(imageSrc, Outlook.OlAttachmentType.olByValue, null, attachmentDisplayName);
mailItem.Subject = "Sending an embedded image";
string imageContentid = "someimage.jpg"; // Content ID can be anything. It is referenced in the HTML body
oAttach.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", imageContentid);
mailItem.HTMLBody = String.Format(
"<body>Hello,<br><br>This is an example of an embedded image:<br><br><img src=\"cid:{0}\"><br><br>Regards,<br>Tarik</body>",
imageContentid);
// Add recipient
Outlook.Recipient recipient = mailItem.Recipients.Add("john#example.com");
recipient.Resolve();
// Send.
mailItem.Send();
}
}
}
From what I can tell, you are not setting the content id properly. Try to change the code to the following:
attc.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F", "image/bmp");
attc.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "Bitmap1.bmp#EMBED");
I have done this before a little differently. I embedded images in some emails that I had to send from my web app using an 'alternate view' in the system.net.mail
System.Net.Mail.LinkedResource theContent = new System.Net.Mail.LinkedResource({path to image});
theContent.ContentID = "TheContent";
String altViewString = anEmail.Body.replace("{original imageSource i.e. '../Images/someimage.gif'}","cid:TheContent");
System.Net.Mail.AlternateView altView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(altViewString, Nothing, System.Net.Mime.MediaTypeNames.Text.Html);
altView.LinkedResources.add(theContent);
anEmail.Message.AlternateViews.Add(altView);
Here's a simple solution:
private static void insertPictureAsLink(Outlook.MailItem mail, String imagePath, String URI)
{
mail.BodyFormat = OlBodyFormat.olFormatHTML;
mail.HTMLBody += String.Format("<body></body>", imagePath, URI);
mail.Display(false);
}
I'm developing a desktop application that has mail sending option. I have the following code to that and it works perfect for only 1 recipient:
DialogResult status;
status = MessageBox.Show("Some message", "Info", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (status == DialogResult.OK)
{
try
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody = "<html>" +
"<body>" +
"some html text" +
"</body>" +
"</html>";
int iPosition = (int)oMsg.Body.Length + 1;
//Subject line
oMsg.Subject = txt_mailKonu.Text;
oMsg.Importance = Outlook.OlImportance.olImportanceHigh;
// Recipient
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
//Following line causes the problem
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(senderForm.getRecipientList().ToString());
oRecip.Resolve();
//oRecip.Resolve();
// Send.
oMsg.Send();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;
MessageBox.Show("Successful", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception)
{
MessageBox.Show("Failed", "Eror", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
I get the error at the bold line where I'm adding multiple recipients in the following pattern:
john.harper#abcd.com; adam.smith#abcd.com
It works fine for 1 address but when I get multiple addresses separated it throws COM Exception - Outlook cannot resolve one or more names.
Hope you'll help me with this.
Did you try to add multiple recipients to oMsg.Recipients?
// I assume that senderForm.getRecipientList() returns List<String>
foreach(String recipient in senderForm.getRecipientList())
{
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
oRecip.Resolve();
}
If needed, you could explode senderForm.getRecipientList().ToString() with
String [] rcpts = senderForm.getRecipientList().ToString().Split(new string[] { "; " }, StringSplitOptions.None);
and use new object in foreach loop.
i want to save the contents of the Email Body in outlook to a file. I am able to save the entire message .msg but i want to save only the html content of the body.
for example:
In the outlook email body i have a table i want to save that table to a file.
the script which i am working on:
public void GetAttachments()
{
Microsoft.Office.Interop.Outlook.Application myolApp = default(Microsoft.Office.Interop.Outlook.Application);
Microsoft.Office.Interop.Outlook.NameSpace ns = default(NameSpace);
MAPIFolder Inbox = default(MAPIFolder);
object Item = null;
Attachment Atmt = default(Attachment);
string FileName = null;
string subject = null;
string AttachmentName = null;
string Body = null;
string SenderName = null;
string SenderEmailAddress = null;
string CreationTime = null;
int i = 0;
int j = 0;
try
{
myolApp = (Microsoft.Office.Interop.Outlook.Application)Interaction.CreateObject("Outlook.Application","");
ns = myolApp.GetNamespace("MAPI");
ns.Logon("", "", false, true);
Inbox = ns.Folders["Mailbox - Name"].Folders["Inbox"];
i = 0;
j = 1;
//Scan for attachments
foreach (object Item_loopVariable in Inbox.Items)
{
Item = Item_loopVariable;
System.Windows.Forms.Application.DoEvents();
if ((Item as MailItem) != null ? ((MailItem)Item).UnRead : false)
{
Body = ((Microsoft.Office.Interop.Outlook.MailItem)Item).Body;
((Microsoft.Office.Interop.Outlook.MailItem)Item).HTMLBody = Body;
((Microsoft.Office.Interop.Outlook.MailItem)Item).SaveAs(#"\\path\"+"filename", Microsoft.Office.Interop.Outlook.OlSaveAsType.olHTML );
j = j + 1;
}
}
//Clear Memory
Atmt = null;
Item = null;
ns = null;
}
catch (System.Exception ex)
{
MessageBox.Show("An unexpected error has occurred."
+ "\r\n" + "Please note and report the following information."
+ "\r\n" + "Script Name: GetAttachments"
+ "\r\n" + "Error Description: " + ex.Message
+ "\r\n" + "Error StackTrace: " + ex.StackTrace
, "Error!");
Atmt = null;
Item = null;
ns = null;
}
}
I need changes in these piece of code:
Body = ((Microsoft.Office.Interop.Outlook.MailItem)Item).Body;
((Microsoft.Office.Interop.Outlook.MailItem)Item).HTMLBody = Body;
((Microsoft.Office.Interop.Outlook.MailItem)Item).SaveAs(#"\\path\"+"filename", Microsoft.Office.Interop.Outlook.OlSaveAsType.olHTML );
Outlook has some issues with saving the body of an email, as far as the filesystem security goes. A workaround is to use the file system objects to save the body - worked for me.