C # connect Exchange send mail

Source: Internet
Author: User
Tags mail code smtpclient

C # Connect Exchange send mail code as follows

<summary>///Exchange bulk mail///</summary>//<param name= "Credentialusername" >        Exchange user name [example:test]</param>//<param name= "credentialuserpwd" >exchange user password </param> <param name= "Fromemail" > Sender Address [Example: [email protected]]</param>//<param name=] Reci Pientemail "> Recipient address </param>//<param name=" DomainName "> Mail domain name [EXAMPLE:MAIL.ALLBRING.COM]&LT;/PARAM&G        T <param name= "Subjectname" > Email subject </param>//<param name= "bodyval" > Message content </param>// /<param name= "ishtml" > whether html</param>//<param name= "Filearray" > Send upload path </param>/ <returns></returns>//Developer: ZJ public static bool Sendexchangeemails (String Credentialuserna Me, String credentialuserpwd, String fromemail, list<string> recipientemail, String domainName, String subjectname , String Bodyval, bool ishtml, string[] filearray) {try {mailmessage message = new Mailmessa                GE ();                MailAddress fromaddress = new MailAddress (fromemail); foreach (string item in Recipientemail) {message.                To.add (item); } message.                from = fromaddress; Message.                Subject = Subjectname; Message.                Body = Bodyval; Message.                isbodyhtml = ishtml;                    if (Filearray! = null) {for (int i = 0; i < filearray.length; i++) {//Create file attachment for message Attachment attr = new Attachment (Filearray[i], mediatypename                        S.application.octet); Add message timestamp information contentdisposition Condispositon = attr.                        Contentdisposition; Condispositon.creationdate = System.IO.File.GetCreationTime (Filearray[i]);//FileCreation Date Condispositon.modificationdate = System.IO.File.GetLastWriteTime (Filearray[i]);//Modified date of File                        Condispositon.readdate = System.IO.File.GetLastAccessTime (Filearray[i]);//Read date of File Add an attachment message to the message.                    Attachments.Add (attr);                }} smtpclient SmtpClient = new SmtpClient ();                Smtpclient.timeout = 50000;                Smtpclient.host = DomainName;                Smtpclient.port = 25;                Smtpclient.usedefaultcredentials = false;                Smtpclient.credentials = new System.Net.NetworkCredential (Credentialusername, credentialuserpwd);                Smtpclient.enablessl = true;                Smtpclient.deliverymethod = Smtpdeliverymethod.network;                Smtpclient.send (message);                Smtpclient.dispose ();            return true; } catch (Exception) {return FALSe }        }

Reference Address: https://social.technet.microsoft.com/Forums/en-US/d37c7e8a-6d42-498a-bad4-5eb0ab7e9d40/ Connecting-to-exchange-server-using-c-to-send-an-email?forum=exchangesvrdevelopment

Http://www.systemnetmail.com/faq/2.4.aspx

C # connect Exchange send mail

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.