IM/MS/smtp/send_email.h
dongl f66340dcc0 smtp 合并到 MS 中
添加好友 取好友列表 略有修改
接下再来 要该包类型宏  备份一下
2023-05-16 17:12:05 +08:00

208 lines
9.6 KiB
C++

//
// Created by dongl on 23-5-10.
//
#ifndef IM2_SEND_EMAIL_H
#define IM2_SEND_EMAIL_H
#include <string>
#include "smtp.h"
#define DOMAIN "smtp.163.com" //smtp服务器域名
#define PORT 25 //smtp服务器域名
#define DEF_SEND_EMAIL "imbaseemail@163.com" //发件人的邮箱地址
#define DEF_SEND_EMAIL_PASS "XIALXUWEOCDPIYAC" //发件人密码
#define CODE_HTML_TEMPLATE(code) get_code_template(code)
std::string get_code_template(const std::string& code);
bool send_email_def(const std::string& target_email, const std::string& code) {
Jxiepc::Smtp smtp(
PORT, //服务器端口(默认25)
DOMAIN, //smtp服务器域名
DEF_SEND_EMAIL, //发件人的邮箱地址
DEF_SEND_EMAIL_PASS, //发件人密码
target_email, //收件人
code + " 是你的IM验证码", //主题
CODE_HTML_TEMPLATE(code), //内容
"html"
);
return smtp.getRet();
}
bool send_email_def(const std::string& send_email, const std::string& password, const std::string& target_email, const std::string& code) {
Jxiepc::Smtp smtp(
PORT, //服务器端口(默认25)
DOMAIN, //smtp服务器域名
send_email, //发件人的邮箱地址
password, //发件人密码
target_email, //收件人
code + " 是你的IM验证码", //主题
CODE_HTML_TEMPLATE(code), //内容
"html"
);
return smtp.getRet();
}
std::string get_code_template(const std::string& code) {
std::string emaialcode[code.size()];
for (int i = 0; i < code.size(); ++i) {
emaialcode[i] = code[i];
}
return "<!DOCTYPE html>\n"
"<html lang=\"en\" xmlns:th=\"http://www.thymeleaf.org\">\n"
"<head>\n"
" <meta charset=\"UTF-8\">\n"
" <title>邮箱验证码</title>\n"
" <style>\n"
" table {\n"
" width: 700px;\n"
" margin: 0 auto;\n"
" }\n"
" #top {\n"
" width: 700px;\n"
" border-bottom: 1px solid #ccc;\n"
" margin: 0 auto 30px;\n"
" }\n"
" #top table {\n"
" font: 12px Tahoma, Arial, 宋体;\n"
" height: 40px;\n"
" }\n"
" #content {\n"
" width: 680px;\n"
" padding: 0 10px;\n"
" margin: 0 auto;\n"
" }\n"
" #content_top {\n"
" line-height: 1.5;\n"
" font-size: 14px;\n"
" margin-bottom: 25px;\n"
" color: #4d4d4d;\n"
" }\n"
" #content_top strong {\n"
" display: block;\n"
" margin-bottom: 15px;\n"
" }\n"
" #content_top strong span {\n"
" color: #f60;\n"
" font-size: 16px;\n"
" }\n"
" #verificationCode {\n"
" color: #f60;\n"
" font-size: 24px;\n"
" }\n"
" #content_bottom {\n"
" margin-bottom: 30px;\n"
" }\n"
" #content_bottom small {\n"
" display: block;\n"
" margin-bottom: 20px;\n"
" font-size: 12px;\n"
" color: #747474;\n"
" }\n"
" #bottom {\n"
" width: 700px;\n"
" margin: 0 auto;\n"
" }\n"
" #bottom div {\n"
" padding: 10px 10px 0;\n"
" border-top: 1px solid #ccc;\n"
" color: #747474;\n"
" margin-bottom: 20px;\n"
" line-height: 1.3em;\n"
" font-size: 12px;\n"
" }\n"
" #content_top strong span {\n"
" font-size: 18px;\n"
" color: #FE4F70;\n"
" }\n"
" #sign {\n"
" text-align: right;\n"
" font-size: 18px;\n"
" color: #FE4F70;\n"
" font-weight: bold;\n"
" }\n"
" #verificationCode {\n"
" height: 100px;\n"
" width: 680px;\n"
" text-align: center;\n"
" margin: 30px 0;\n"
" }\n"
" #verificationCode div {\n"
" height: 100px;\n"
" width: 680px;\n"
" }\n"
" .button {\n"
" color: #FE4F70;\n"
" margin-left: 10px;\n"
" height: 80px;\n"
" width: 80px;\n"
" resize: none;\n"
" font-size: 42px;\n"
" border: none;\n"
" outline: none;\n"
" padding: 10px 15px;\n"
" background: #ededed;\n"
" text-align: center;\n"
" border-radius: 17px;\n"
" box-shadow: 6px 6px 12px #cccccc,\n"
" -6px -6px 12px #ffffff;\n"
" }\n"
" .button:hover {\n"
" box-shadow: inset 6px 6px 4px #d1d1d1,\n"
" inset -6px -6px 4px #ffffff;\n"
" }\n"
" </style>\n"
"</head>\n"
"<body>\n"
"<table>\n"
" <tbody>\n"
" <tr>\n"
" <td>\n"
" <div id=\"top\">\n"
" <table>\n"
" <tbody><tr><td></td></tr></tbody>\n"
" </table>\n"
" </div>\n"
" <div id=\"content\">\n"
" <div id=\"content_top\">\n"
" <strong>尊敬的用户:您好!</strong>\n"
" <strong>\n"
" 您正在进行<span>注册账号</span>操作,请在验证码中输入以下验证码完成操作:\n"
" </strong>\n"
" <div id=\"verificationCode\">\n"
" <button class=\"button\">"+emaialcode[0]+"</button>\n"
" <button class=\"button\">"+emaialcode[1]+"</button>\n"
" <button class=\"button\">"+emaialcode[2]+"</button>\n"
" <button class=\"button\">"+emaialcode[3]+"</button>\n"
" <button class=\"button\">"+emaialcode[4]+"</button>\n"
" <button class=\"button\">"+emaialcode[5]+"</button>\n"
" </div>\n"
" </div>\n"
" <div id=\"content_bottom\">\n"
" <small>\n"
" 注意:此操作可能会修改您的密码、登录邮箱或绑定手机。如非本人操作,请及时登录并修改密码以保证帐户安全\n"
" <br>(工作人员不会向你索取此验证码,请勿泄漏!)\n"
" </small>\n"
" </div>\n"
" </div>\n"
" <div id=\"bottom\">\n"
" <div>\n"
" <p>此为系统邮件,请勿回复<br>\n"
" 请保管好您的邮箱,避免账号被他人盗用\n"
" </p>\n"
" <p id=\"sign\">——IM Base Email</p>\n"
" </div>\n"
" </div>\n"
" </td>\n"
" </tr>\n"
" </tbody>\n"
"</table>\n"
"</body>\n";
}
#endif //IM2_SEND_EMAIL_H