C # using Cdo.message to send mail, the success rate is extremely high

Source: Internet
Author: User
Using CDO;

Using System; Namespace ConsoleApp1 {class Program {static void Main (string[] args) {string from
            = "XXX";
            string to = "xxx";
            String userName = from;
            string password = "xxx";
            string title = "Test Message";
            String BODY = "Hello, how are you doing?";
            String server = "Smtp.126.com";  int port = 25;
                SSL 465 try {SendEmail (from, to, title, body, password, server, port, false);
            Console.WriteLine ("Send Complete");
            catch (Exception) {throw new Exception ();
        } console.readkey (); public static bool SendEmail (string from, string to, string title, string body, string password, string server
            , int port, BOOL SSL) {BOOL flag = false; try {#region MessaGE omsg = new message ();
                var conf = omsg.configuration; var ofields = conf.

                Fields; ofields["Http://schemas.microsoft.com/cdo/configuration/sendusing"].
                Value = Cdosendusing.cdosendusingport; ofields["Http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].
                Value = Cdoprotocolsauthentication.cdobasic; if (SSL) {ofields["Http://schemas.microsoft.com/cdo/configuration/smtpusessl"].
                Value = true; } ofields["Http://schemas.microsoft.com/cdo/configuration/smtpserver"]. Value = server;//must be filled in, and the ofields["Http://schemas.microsoft.com/cdo/configuration/smtpserverport" can be used for real. Value = port;//Mailbox Port ofields["Http://schemas.microsoft.com/cdo/configuration/sendemailaddress"]. Value = from;//Sender mailbox ofields["Http://schemas.microsoft.com/cdo/configuration/sendusername"].   
           Value = from;//Mailbox Sender Name     ofields["Http://schemas.microsoft.com/cdo/configuration/sendpassword"].   Value = password;

                e-mail sender password, must be true ofields.update ();
                omsg.configuration = conf; oMsg.Subject = title;//Theme omsg.htmlbody = body;//message body oMsg.From = fr
                om;//Sender omsg.to = to;//receiver Omsg.send ();//Send flag = true;
                #endregion} catch (Exception) {flag = false;
            throw new Exception ();
        return flag;
 }
    }
}

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.