Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Outlook Interop在电子邮件中嵌入图像_C#_Image_Email - Fatal编程技术网

C# 使用Outlook Interop在电子邮件中嵌入图像

C# 使用Outlook Interop在电子邮件中嵌入图像,c#,image,email,C#,Image,Email,我有一个简单的小电子邮件应用程序,允许用户选择生成字符串并发送电子邮件的特定选项。我想看看是否有可能在电子邮件中添加图像,如标题徽标或签名等。我一直在看的研究非常注重HTML,我对HTML了解很少。有人能帮忙吗?我的代码如下 using System; using Outlook = Microsoft.Office.Interop.Outlook; using System.Configuration; namespace My_EmailSender { public class

我有一个简单的小电子邮件应用程序,允许用户选择生成字符串并发送电子邮件的特定选项。我想看看是否有可能在电子邮件中添加图像,如标题徽标或签名等。我一直在看的研究非常注重HTML,我对HTML了解很少。有人能帮忙吗?我的代码如下

using System;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Configuration;

namespace My_EmailSender
{
    public class EmailSender:Notification
    {
        string emailRecipient = ConfigurationManager.AppSettings["emailRecipient"];

        public void SendMail(string message)
        {
            try
            {
                var oApp = new Outlook.Application();
                var oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                var oRecip = (Outlook.Recipient)oMsg.Recipients.Add(emailRecipient);
                oRecip.Resolve();
                oMsg.Subject = "Email Notification";
                oMsg.Body = message;

                // Display the message before sending could save() also but no need
                oMsg.Send();
                oMsg.Display(true);
                oRecip = null;
                oMsg = null;
                oApp = null;
            }
            catch (Exception e)
            {
                Console.WriteLine("Problem with email execution. Exception caught: ", e);
            }

            return;
        }
    }
}

我总是使用
System.Net.Mail
发送电子邮件,但这可能是您的要求吗


以下是通过outlook在c中发送图像的示例代码#

Configuration config=System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Request.ApplicationPath);
System.Net.Configuration.MailSettingsSectionGroup设置=(System.Net.Configuration.MailSettingsSectionGroup)config.GetSectionGroup(“System.Net/mailSettings”);
System.Net.Configuration.SmtpSection smtp=settings.smtp;
System.Net.Configuration.SmtpNetworkElement network=smtp.network;
Microsoft.Office.Interop.Outlook.Application outlookApp=新的Microsoft.Office.Interop.Outlook.Application();
MailItem MailItem=(MailItem)outlookApp.CreateItem(OlimType.olMailItem);
mailItem.To=network.TargetName;
附件附件=mailItem.Attachments.Add(
“C://test.bmp”
,OlAttachmentType.olEmbeddeditem
无效的
,“测试图像”
);
string imageCid=“测试。bmp@123";
附件.PropertyAccessor.SetProperty(
"http://schemas.microsoft.com/mapi/proptag/0x3712001E"
,imageCid
);
mailItem.BodyFormat=OlBodyFormat.olFormatRichText;
mailItem.HTMLBody=String.Format(
""
,imageCid
);
mailItem.Importance=OlImportance.olImportanceNormal;
mailItem.Display(false);


使用net.mail非常简单,但是,如果您希望发送大量电子邮件,我建议您使用SendBlaster程序。
        Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(HttpContext.Request.ApplicationPath);
        System.Net.Configuration.MailSettingsSectionGroup settings = (System.Net.Configuration.MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
        System.Net.Configuration.SmtpSection smtp = settings.Smtp;
        System.Net.Configuration.SmtpNetworkElement network = smtp.Network;
        Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
        MailItem mailItem = (MailItem)outlookApp.CreateItem(OlItemType.olMailItem);
        mailItem.To = network.TargetName;


        Attachment attachment = mailItem.Attachments.Add(
        "C://test.bmp"
        , OlAttachmentType.olEmbeddeditem
        , null
        , "test image"
        );
        string imageCid = "test.bmp@123";

        attachment.PropertyAccessor.SetProperty(
            "http://schemas.microsoft.com/mapi/proptag/0x3712001E"
            , imageCid
            );
        mailItem.BodyFormat = OlBodyFormat.olFormatRichText;
        mailItem.HTMLBody = String.Format(
              "<body><img src=\"cid:{0}\"></body>"
             , imageCid
             );

        mailItem.Importance = OlImportance.olImportanceNormal;
        mailItem.Display(false);