when i want to forward a MailItem, how can i use olRuleActionForwardAsAttachme?
When i want to forward a MailItem, i want to use ForwardAsAttachment, how can i use olRuleActionForwardAsAttachme?
Any one know it?
When i want to forward a MailItem, i want to use ForwardAsAttachment, how can i use olRuleActionForwardAsAttachme?
Any one know it?
olRuleActionForwardAsAttachment is a constant used in creating a rule, not in creating a new message.
To forward a MailItem, create a new message either with CreateObject or MailItem.Forward, then use the MailItem.Attachments.Add method to add the desired item as an attachment. If you use MailItem.Forward, you'll probably want to clear the Body property.
foreach (MailItem mi in applicationObject.ActiveExplorer().Selection)
{
if (mi != null)
{
MailItem miForward = (MailItem)applicationObject.CreateItem(OlItemType.olMailItem);
Attachment at = miForward.Attachments.Add(mi, Type.Missing, 0, nameSubject);
miForward.Subject = mi.Subject;
miForward.Save();
Outlook.PropertyAccessor oPropAccessor;
string PR_MAIL_HEADER_TAG = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/ExcutiveTag";
oPropAccessor = miForward.PropertyAccessor;
miForward.To = Properties.Settings.Default.TagServerEmail;
oPropAccessor.SetProperty(PR_MAIL_HEADER_TAG, "1");
miForward.BodyFormat = OlBodyFormat.olFormatPlain;
miForward.Save();
miForward.Send();
}
}
I can not find the attachment filename in the email source, how can i see the attachment name?
Something like this in the eamil source:
=_NextPart_000_0005_01C7D430.0E33E830
Content-Type: message/rfc822
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment
No file name is involved when an Outlook item is attached. If your application requires a file name, save the message you want to forward as an .msg file, then attach that file.
Thanks for your replay! I have try it, but i got another issue, when i save the TaskItem as a file and attach it to mail, when i receive the emial and check the attachment, when i open it, it shows as a normal mail, not show as a TaskItem? why?
foreach (TaskItemobj in applicationObject.ActiveExplorer().Selection)
{
try
{
bool blTaged = false;
string strSubject = "";
string strFileName = "";
string strTypeName="";
OlItemType oit= OlItemType.olMailItem;
if (obj is Outlook.TaskItem)
{
TaskItem mi = obj as TaskItem;
if (mi.ItemProperties["ExcutiveTaged"] == null)
{
ItemProperty prop = mi.ItemProperties.Add("ExcutiveTaged", OlUserPropertyType.olYesNo, true, Missing.Value);
prop.Value = true;
mi.Save();
strSubject = mi.Subject;
strFileName = mi.Subject.Replace(":", "").Replace("\\", "").Replace("\"", "").Replace("/", "").Replace("?", "").Replace("|", "");
strTypeName = "TaskItem";
oit = OlItemType.olTaskItem;
mi.SaveAs(Properties.Settings.Default.TempPath + strFileName + ".msg", Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSG);
}
else
{
blTaged = true;
}
}
#endregion
if (blTaged == false)
{
miForward.Attachments.Add(Properties.Settings.Default.TempPath + strFileName + ".msg", OlAttachmentType.olByValue, Type.Missing, strFileName + ".msg");
miForward.Subject = strSubject;
miForward.To = Properties.Settings.Default.TagServerEmail;
miForward.Send();
System.IO.File.Delete(Properties.Settings.Default.TempPath + strFileName + ".msg");
}
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
You may need to set the format of the transmitting message to rich-text, using the BodyFormat property.
Thank you very much! but the issue dose not resolve.
I add this code:
miForward.BodyFormat = OlBodyFormat.olFormatRichText;
but I get same result as before. I have try to forward a TaskItem to a email box, I also got the same result. it is not a TaskItem.
Any ideal about this?
Does the message arrive at its destination as a rich-text message? If not, then the problem may be that one of the mail servers -- probably the outgoing -- is stripping RTF content or Outlook is set to convert rich-text messages to HTML.
It is dose not work, i have change the setting of Mail format, and i send a email using richtext fromat, i got same result.
But if i zip that msg file and send out, it is ok.
I can do it by this way, but i am just wondering why?
Again, you don't have complete control over the mail format. The sending (most likely) or receiving server could be stripping the RTF content. One way to find out if that is happening is to send to an account like Gmail, where you can see the full RFC822 message and determine whether the Winmail.dat file that includes the RTF content is still present.