1

Microsoft Word ドキュメントを Microsoft Outlook 電子メールの本文として使用しようとしています。これまでのところ、次のコードを使用して、Word .docx のテキストを電子メールの本文に含めることができました。

            if (File.Exists(fileName.ToString()))
        {
            DateTime today = DateTime.Now;

            object readOnly = false;
            object isVisible = false;

            //Set Word to invisible
            wordApp.Visible = false;

            //Open the word document
            aDoc = wordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing,
                ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);

            try
            {
                //Activate Document
                aDoc.Activate();

                //Find Place Holders and replace them with values
                this.FindAndReplace(wordApp, "<NameAddressed>", NameAddressed);
                this.FindAndReplace(wordApp, "<SessionInfo>", SessionInfo);
                this.FindAndReplace(wordApp, "<NumberGuests>", GuestNumber);
                this.FindAndReplace(wordApp, "<Balance>", Balance);

                //Postal
                this.FindAndReplace(wordApp, "<FullName>", FullName);
                this.FindAndReplace(wordApp, "<Address1>", Address1);
                if (Address2 != "&nbsp" && Address2 != "" && Address2 != " ")
                    this.FindAndReplace(wordApp, "<Address1>", Address1 + "\n\r" + Address2);
                else
                    this.FindAndReplace(wordApp, "<Address1>", Address1);
                this.FindAndReplace(wordApp, "<City>", City);
                this.FindAndReplace(wordApp, "<State>", State);
                this.FindAndReplace(wordApp, "<Zip>", Zip);
            }
            catch (Exception ex)
            {
                aDoc.Close(ref missing, ref missing, ref missing);
                ClientScript.RegisterStartupScript(this.GetType(), "error", "javascript:;alert('" + ex.Message + "')");
                return false;
            }
            aDoc.SaveAs(ref saveAs);

            //Save the file as the correct file name

            if (DataType.Text == "Email")
            {
                Outlook.Application oApp = new Outlook.Application();
                // Create a new mail item.
                Outlook.MailItem eMail = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

                Word.Range r = aDoc.Content;
                r.Select();
                string s = r.Text;

                eMail.Subject = "Confirmation Email";
                eMail.To = "example@xyz.com";
                eMail.Body = s;
                ((Outlook._MailItem)eMail).Send();
                //Close the document - you have to do this
                aDoc.Close(ref missing, ref missing, ref missing);
            }
            litError.Text = "File Created. ";
            return true;
        }
        else
        {
            litError.Visible = true;
            litError.Text = "File Does Not Exist";
            return false;
        }

ただし、このコードには、電子メールの Word ドキュメントにもある画像は含まれません。.docx の画像を Outlook に送信し、元の形式を維持する方法はありますか? 前もって感謝します

4

1 に答える 1

1

まず、プレーン テキストMailItem.Bodyプロパティを設定しています。次に、添付ファイルを作成し、 を使用してPR_ATTACH_CONTENT_IDプロパティ (DASL 名"http://schemas.microsoft.com/mapi/proptag/0x3712001F") を設定しますAttachment.PropertyAccessor.SetProperty

HTML 本文 (MailItem.HTMLBodyプロパティ) は、cid 属性を介してその画像添付ファイルを参照する必要があります。

<img src="cid:xyz">

ここで、xyz はPR_ATTACH_CONTENT_IDプロパティの値です。

OutlookSpyで既存のメッセージを確認します ([ IMessage ] ボタンをクリックします)。

EDIT:サンプルスクリプト(私の頭の上から):

attachment = MailItem.Attachments.Add("c:\temp\MyPicture.jpg")
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyId1")
MailItem.HTMLBody = "<html><body>Test image <img src=""cid:MyId1""></body></html>"
于 2013-06-19T17:01:24.363 に答える