"C #" #102 sending mail

Source: Internet
Author: User
Tags mailmessage smtpclient

Project requirements: Send emails at regular intervals and learn how to send emails

Here's a simple example. The ability to implement a simple send message, plus an attachment can add a property "Attachment", and then configure the path to the attachment

Demo download

The code has only a few of these, so you can send mail.

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Net.Mail;namespacesendmail{ Public classEmailhelper {/// <summary>        ///Send mail/// </summary>        /// <param name= "from" > Sender </param>        /// <param name= "to" > Recipients </param>        /// <param name= "title" > title </param>        /// <param name= "Body" > Email content </param>        /// <returns></returns>         Public Static BOOLSend (mailaddress from,stringTo,stringSubjectstringbody) {MailMessage MailMessage=NewMailMessage (); Mailmessage.from= from;            MAILMESSAGE.TO.ADD (to); MAILMESSAGE.TO.ADD ("[email protected]"); MAILMESSAGE.TO.ADD ("[email protected]"); Mailmessage.subject=subject; Mailmessage.body=body; Mailmessage.isbodyhtml=false; Mailmessage.priority=Mailpriority.high; SmtpClient SC=NewSmtpClient (); Sc. Host="smtp.qq.com";//If you use a non-QQ mailbox, you need to replaceSc. Port = -; Sc. useDefaultCredentials=true; Sc. Enablessl=false; Sc. Credentials=NewSystem.Net.NetworkCredential ("Account Number","Password"); Try{SC.            Send (MailMessage); }            Catch(Exception E1) {//throws an exception, does not process, lets the caller handle                ThrowE1; }            return true; }    }}

"C #" #102 sending 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.