none
RRS feed

Answers

  • Hi,

    Based on my understanding, you want to get the attachment file information and add it in mail body, If you want to calculate MD5 when adding an attachment, I suggest you to add a new Ribbon button ,and then calculate MD5 form file path and add attachment,The follow code can calculate MD5 and SHA1 from file name.

    using (var stream = File.OpenRead(FileName))
                {
                    using (var md5 = MD5.Create())
                    {
                        FileMd5 = BitConverter.ToString(md5.ComputeHash(stream));
                    }
                    using (SHA1Managed sha1 = new SHA1Managed())
                    {
                        SHA1 = BitConverter.ToString(sha1.ComputeHash(stream));
                    }
                }

    If you want calculate MD5 in an existing mail, I suggest him to export the attachment to a temp folder since we couldn’t read binary attachment directly via current API,and then calculate MD5 and SHA1.

    Attachment.SaveAsFile(System.Environment.GetEnvironmentVariable("TEMP"));

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Marvin_Guo Tuesday, January 7, 2014 1:41 AM
    Tuesday, December 31, 2013 8:26 AM
  • Hello Brijesh,

    You can use the Send method of the MailItem class for sending e-mails programmatically. For example:

    Outlook.MailItem mail = Application.CreateItem(
    Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    mail.Subject = "subject goes here";
    mail.Recipients.Add("email@address.com");
    mail.Recipients.ResolveAll();
    // add an attahcment if needed
    mail.Attachments.Add(@"c:\sales reports\report.xlsx",
                Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
    mail.Send();
    

    The Body or HTMLBody properties can be used for adding the required info about attachments. Unfortunately the Attachment class doesn't provide any property for getting the content of the attached file. You have to save the attached file on the disk, which is a time-consuming task. Also, as a workaround, you can use the PropertyAccessor for small files under 16 Kb for getting the PR_ATTACH_DATA_BIN property (the DASL property - "http://schemas.microsoft.com/mapi/proptag/0x37010102").

    • Marked as answer by Marvin_Guo Tuesday, January 7, 2014 1:41 AM
    Tuesday, December 31, 2013 12:58 PM

All replies

  • Hi,

    Based on my understanding, you want to get the attachment file information and add it in mail body, If you want to calculate MD5 when adding an attachment, I suggest you to add a new Ribbon button ,and then calculate MD5 form file path and add attachment,The follow code can calculate MD5 and SHA1 from file name.

    using (var stream = File.OpenRead(FileName))
                {
                    using (var md5 = MD5.Create())
                    {
                        FileMd5 = BitConverter.ToString(md5.ComputeHash(stream));
                    }
                    using (SHA1Managed sha1 = new SHA1Managed())
                    {
                        SHA1 = BitConverter.ToString(sha1.ComputeHash(stream));
                    }
                }

    If you want calculate MD5 in an existing mail, I suggest him to export the attachment to a temp folder since we couldn’t read binary attachment directly via current API,and then calculate MD5 and SHA1.

    Attachment.SaveAsFile(System.Environment.GetEnvironmentVariable("TEMP"));

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Marvin_Guo Tuesday, January 7, 2014 1:41 AM
    Tuesday, December 31, 2013 8:26 AM
  • Hello Brijesh,

    You can use the Send method of the MailItem class for sending e-mails programmatically. For example:

    Outlook.MailItem mail = Application.CreateItem(
    Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    mail.Subject = "subject goes here";
    mail.Recipients.Add("email@address.com");
    mail.Recipients.ResolveAll();
    // add an attahcment if needed
    mail.Attachments.Add(@"c:\sales reports\report.xlsx",
                Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
    mail.Send();
    

    The Body or HTMLBody properties can be used for adding the required info about attachments. Unfortunately the Attachment class doesn't provide any property for getting the content of the attached file. You have to save the attached file on the disk, which is a time-consuming task. Also, as a workaround, you can use the PropertyAccessor for small files under 16 Kb for getting the PR_ATTACH_DATA_BIN property (the DASL property - "http://schemas.microsoft.com/mapi/proptag/0x37010102").

    • Marked as answer by Marvin_Guo Tuesday, January 7, 2014 1:41 AM
    Tuesday, December 31, 2013 12:58 PM