2011-12-04 3 views
1

안녕하세요. Outlook 추가 기능을 개발 중입니다. 작업 흐름의 일부로 mailItem 본문 및 제목을 사용해야하며 각받는 사람마다 메시지 본문을 변경해야합니다. 받는 사람 전자 메일로 보냅니다. Outlook MailItem 루프를 사용하여 여러 전자 메일 보내기

문제

은 단지 첫 번째 전자 메일을 보내는하고 Send(); 후에는 다른 수신자

Outlook.Application application = Globals.ThisAddIn.Application; 
     Outlook.Inspector inspector = application.ActiveInspector(); 
     Outlook.MailItem myMailItem = (Outlook.MailItem)inspector.CurrentItem; 
     myMailItem.Save(); 



     if (myMailItem != null) 
     { 

      myMailItem.Save(); 
      PorceesData(myMailItem); 
     } 

      .. 
      .. 
      .. 
      .. 
    private void ProcessData(MailItem oMailItem) 
     { 

Recipients recipients = oMailItem.Recipients; 

string Body = oMailItem.Body; 
string To = oMailItem.To; 
string CC = oMailItem.CC; 
string bcc = oMailItem.BCC; 

foreach (Recipient r in recipients) 
{ 
    if (r.Resolve() == true) 
    { 

     string msg = "Hello open the attached file (msg.html); 
     string address = r.Address; 
     oMailItem.Body = msg; 
     oMailItem.To = address; 
     oMailItem.Subject = "my subject" 

     foreach (Attachment t in oMailItem.Attachments) 
     { 
       t.Delete(); 
      } 

      oMailItem.Attachments.Add(@"mydirectory"); 

      oMailItem.Send(); 
} 
+1

작성한 코드를 친절하게 보여주십시오. – Shai

+1

코드 – user1067812

+0

을 추가하고 게시했습니다. 'oMailItem.Recipients'를 통해 iterating하고 있습니다. 수신자 목록을 가져옵니다 ...? – Shai

답변

2

_MailItem.Send() 현재 관리자를 닫으로 전자 메일을 보내지 않습니다. 이것은 _MailItem.Send documentation에 없지만 실제 Outlook 구현입니다. 당신은 아마 다른 접근법을 생각해 내야합니다. 보내려는 각 메시지에 대해 새로운 MailItem 인스턴스를 만드는 것이 좋습니다.

당신이 만들 수있는 새로운 MailItem 사용 ...

Outlook.MailItem eMail = (Outlook.MailItem) 
Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem); 
eMail.Subject = subject; 
eMail.To = toEmail; 
eMail.Body = body; 
eMail.Importance = Outlook.OlImportance.olImportanceLow; 
((Outlook._MailItem)eMail).Send(); 

모든받는 사람에게 보낸 후 수동으로 사용하여 현재 관리자를 닫을 수

((Outlook._MailItem)myMailItem).Close(Outlook.OlInspectorClose.olDiscard) 
( Send()는 암시 적으로이 방법를 호출) 다음
+0

대단히 감사합니다. – user1067812

관련 문제