vc编程 UTF-8中文乱码问题解决

USES_CONVERSION; LPSTR strFrom = W2A(mi.wstrFrom); LPSTR strTo = W2A(I_strTo/*mi.wstrTo*/); LPSTR strSubject = W2A(I_strTitle/*mi.wstrSubject*/); LPSTR strServer = W2A(mi.wstrServer); LPSTR strContent = W2A(I_strContent/*mi.wstrContent*/); LPSTR strUser = W2A(mi.wstrUser); LPSTR strPassword = W2A(mi.wstrPwd); char szTemp[8096] = {NULL}; WideCharToMultiByte(CP_UTF8, 0, I_strTitle.GetBuffer(0), -1, szTemp, 8095, NULL, NULL ); char szTemp1[8096] = {NULL}; WideCharToMultiByte(CP_UTF8, 0, I_strContent.GetBuffer(0), -1, szTemp1, 8095, NULL, NULL ); jwsmtp::mailer mail(strTo, strFrom, szTemp/*strSubject*/, szTemp1/*strContent*/, strServer, jwsmtp::mailer::SMTP_PORT, false); if(mi.byAuthorize) { mail.username(strUser); mail.password(strPassword); } if(wcscmp(mi.wstrAttachFile, L"") != 0) { LPSTR strAttachFile = W2A(mi.wstrAttachFile); mail.attach(strAttachFile); } mail.send(); // send the mail

 

 

MIME以及Subject的设置

 

//add by jgli for GB2312 headerline = "MIME-Version: 1.0/r/n" "Content-Type: text/plain; charset=utf-8/r/n" "Content-Transfer-Encoding: 8bit/r/n"; ret.insert(ret.end(), headerline.begin(), headerline.end()); headerline.clear(); //end /////////////////////////////////////////////////////////////////////////// // add the subject std::string b64_title; b64_title = base64encode(subject, false); headerline = "Subject: =?UTF-8?B?" + b64_title + "?=/r/n/r/n"; //CHANGE BY JGLI FOR CHINESE.=?gb2312?B?....?= ret.insert(ret.end(), headerline.begin(), headerline.end());

你可能感兴趣的:(编程,String,null)