Original article: C # create an email in outlook to the draft box
1. Reference Microsoft. Office. InterOP. Outlook. dll
2. Implementation Code
1 public static int sendtodraft (list <string> to, list <string> CC, list <string> BCC, string subject, string content, list <string> attachments, ref string errormessage) 2 {3 int result =-1; 4 try 5 {6 stringbuilder sbattachment = new stringbuilder (); 7 Application objoutlook = new application (); 8 namespace onamespace = objoutlook. getnamespace ("mapi"); 9 mapifolder folder = onamespace. getdefaultfo Lder (oldefaultfolders. olfolderdrafts); 10 mailitem item = (mailitem) (objoutlook. createitem (olitemtype. olmailitem); 11 item. to = getstring (to); 12 item. cc = getstring (CC); 13 item. BCC = getstring (BCC); 14 item. subject = subject; 15 item. htmlbody = content; 16 new log ("Send email outlook "). write ("7"); 17 // Add attachment 18 if (attachments! = NULL & attachments. count> 0) 19 {20 for (INT I = 0; I <attachments. count; I ++) 21 {22 item. attachments. add (@ attachments [I]); 23} 24} 25 item. savesentmessagefolder = folder; 26 item. save (); 27 result = 0; 28} 29 catch (system. exception ex) 30 {31 result =-3; 32 errormessage = ex. message. tostring (); 33} 34 return result; 35}
View code
C # create an email in outlook to the draft box