C # calls Outlook to send a message instance

Source: Internet
Author: User
Tags mail account

Add Reference: Microsoft.Office.Interop.Outlook

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Net.Mail;usingSystem.Net;usingOutlook =Microsoft.Office.Interop.Outlook;namespacecommon{ Public classMailhelper { Public Static voidSendMail () {Outlook.Application olapp=NewOutlook.Application (); Outlook.MailItem MailItem=(Outlook.MailItem) Olapp.createitem (Outlook.OlItemType.olMailItem); Mailitem.to="[email protected]"; Mailitem.subject= DateTime.Now.ToString ("YYYYMMDD") +"_ Report"; MailItem.BodyFormat=Outlook.OlBodyFormat.olFormatHTML; stringContent ="Attachment is"+ DateTime.Now.ToString ("YYYYMMDD") +"data, please check, thank you! "; Content="each recipient,<br/> <br/> please focus on the following:<br/> <br/>"+ content +"<br/> <br/><br/><br/> This message is automatic email notification, please do not reply directly! Thank you. "; Content= content +"<br/>\r\n <br/>best regards!\r\n < ; br/>\r\n <br/> \ r \ <br/>== ============================================\r\n \ r \ < ; br/>\r\n <br/>\r\n \ r \ n ========================== ====================="; Mailitem.htmlbody=content; MAILITEM.ATTACHMENTS.ADD (@"C:\test.rar"); ((Outlook._mailitem) MailItem).            Send (); MailItem=NULL; Olapp=NULL; }    }}

In Microsoft Office Outlook, you need to configure a sender's mail account, and if it is a free mailbox like 163, you need to set up a "client authorization password" and then configure it with this client-authorized password to replace the mailbox's login password . Otherwise, it will not be able to send mail.

After the send is successful as shown:

C # calls Outlook to send a message instance

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.