Add Outlook API
1 using OutLook = Microsoft.Office.Interop.Outlook;
Send Message method
1 Public voidSendEmail ()2 {3Outlook.Application app =Newoutlook.application ();4Outlook.NameSpace ns = App. GetNamespace ("MAPI");5Ns. Logon ("Servername\\username","Password",false,true);6 Outlook.MailItem message = (Outlook.MailItem) app. CreateItem (OutLook.OlItemType.olMailItem); 7Message. Subject ="subject";8Message. to =the account@XXX. com";9Message. Body ="Hello world!";TenMessage. Display (true); One message. Send (); A NS. Logoff (); -}
The compilation error is as follows:
Method "Microsoft.office.interop.outlook._mailitem.send ()" and non-method "Microsoft.Office.Interop.Outlook.ItemEvents_10_ Event.send "There is ambiguity between the two. The method group will be used.
Modify the 6th line in the preceding code snippet to read as follows:
1 OutLook. _mailitem message = (Outlook.MailItem) app. CreateItem (OutLook.OlItemType.olMailItem);
Problem Solving!
Use C # to simulate Outlook sending messages, code compilation error