C + + uses Chilkat library to send HTML messages

Source: Internet
Author: User


Reprint please indicate source: http://blog.csdn.net/yangyihongyangjiying/article/details/44757687 Thank you!

A brief introduction to the Chilkat Library, Chikat is a Chicago company developed by the commercial components, the function is complete, detailed introduction can go to the official website self-reading is not outgoing products or can be used, Chilkat support multiple platforms, voice, see more: http://www.chilkatsoft.com/

C + +: http://www.example-code.com/cpp/default.asp Download the corresponding version of the IDE, in case some strange bug, similar to unresolved external symbol __ Report_rangecheckfailure This log can refer to my blog unresolved external symbol __report_rangecheckfailure to solve the idea

Below is the sending of HTML mail via Chilkat, Demo:


Static string& trim (std::string &s) {if (S.empty ()) {return s;  } s.erase (0,s.find_first_not_of (""));  S.erase (S.find_last_not_of ("") + 1);  return s; }//Note: When the string is empty, an empty string will also be returned static void split (string& s, std::string& Delim, vector<string >* ret) {size_t Last = 0;size_t index = s.find_first_of (Delim,last), while (Index! = std::string::npos) {ret->push_back (S.substr (last , Index-last)); last=index+1;index=s.find_first_of (delim,last);} if (index-last>0) {ret->push_back (S.substr (Last,index-last));}} BOOL Sendhtml (string& suser, string& spwd, string& ssmtphost, string& ssubject, string& sTo, STRING&A mp shtmlcontent) {Ckmailman mailman;//unlocks the device, ckmailman the precondition for normal use bool success = Mailman. Unlockcomponent ("30-day trial"), if (!success) {Log (Log_info, "can not be unlock component."); Set up a mailbox server, for example: Smtp.xx.commailman.put_SmtpHost (Ssmtphost.c_str ());//Set Mailbox login username, password mailman.put_smtpusername (suser.c _str ()); Mailman.put_smtppassword (Spwd.c_str ()); CkEmail email;//Set the message header Email.put_subject (SSUBJECT.C_STR ());//send content email. Sethtmlbody (Shtmlcontent.c_str ());//Sender Email.put_from (SUSER.C_STR ()),//Split recipient below, and add to ckemail one by one vector<string > vtos;string ssplit = ";"; Split (STo, Ssplit, &vtos), Vector<string>::iterator ITos = Vtos.begin (); for (; ITos! = Vtos.end (); ITos + +) {if (! Trim (*itos). Empty ()) {//can only add one user or user group email at a time. AddTo ("", Itos->c_str ());}} Modify the message encoding format to UTF8, this is very important, or some Chinese characters will not be very good display email.put_charset ("UTF8"); success = Mailman. SendEmail (email), if (!success) {Log (Log_error, "ERROR happen to send Email:%s!", Mailman.lasterrortext ()); return false;} Finally close the link success = Mailman. Closesmtpconnection (); if (success! = True) {Log (Log_info, "Connection to SMTP server not closed cleanly."); return true;}


It is important to remind that if the message contains Chinese, it must pass Email.put_charset ("UTF8"); The encoding format of the message is converted to UTF8, so that the Chinese cannot be displayed properly by ASCII code.



C + + uses Chilkat library to send HTML messages

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.