2011-12-12 5 views
1

사용자가 문자열을 생성하고 전자 메일을 보내는 특정 옵션을 선택할 수있는 간단한 전자 메일 앱이 있습니다. 이메일에 이미지를 추가 할 수 있는지, 예를 들어 헤더 로고나 서명 등을보고 싶었습니다. 내가 봤던 연구는 매우 무겁고 HTML이 거의 없습니다. 누구든지 도와 줄 수 있습니까? 다음과 같이 내 코드는 ...Outlook Interop을 사용하여 전자 메일에 이미지 임베드

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; 
     } 
    } 
} 

답변

0

난 항상 이메일을 보내 System.Net.Mail을 사용하지만 어쩌면이 당신의 요구 사항은 무엇입니까? 여기 Read up on system.net.mail here.

+0

net.mail을 아주 쉽게 사용할 수 에 전망을 통해 이미지를 전송하기위한 샘플 코드 많은 이메일을 보내려는 경우 SendBlaster 프로그램을 추천합니다. –

2

그러나, C#을

 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 = "[email protected]"; 

     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); 

관련 문제