You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.9 KiB

#include "CSendMail.h"
#include "boost\algorithm\\string.hpp"
#include "util.h"
int jd_send_mail(EPM_action_message_t msg) {
POM_AM__set_application_bypass(true);
tag_t root_task, *attachments;
int att_cnt;
EPM_ask_root_task(msg.task, &root_task);
EPM_ask_attachments(root_task, EPM_target_attachment, &att_cnt, &attachments);
TC_argument_list_t *arguments = msg.arguments;
int arg_cnt = TC_number_of_arguments(arguments);
map<string, string> paras;
for (auto i = 0; i < arg_cnt; i++) {
char *temp_key, *temp_val;
ITK_ask_argument_named_value(TC_next_argument(arguments), &temp_key, &temp_val);
paras[temp_key] = temp_val;
}
stringstream mail_content;
if (att_cnt <= 0) {
return 0;
}
char *target_str;
//PREF_refresh("jd2_task_target");
//PREF_ask_char_value("jd2_task_target", 0, &target_str);
//ITKCALL(AOM_refresh(root_task, false));
AOM_ask_value_string(root_task, "object_desc", &target_str);
vector<string> target_vec;
//AOM_ask_value_string(root_task, "jd2_task_target", &target_str);
//ifstream in;
//stringstream file_location;
//file_location << getenv("temp");
//file_location << "\\";
//file_location << "jd2_task_target.txt";
//in.open(file_location.str().c_str(), ios::in);
//in >> target_str;
//in.close();
printf("target_str====>%s\n", target_str);
if (tc_strlen(target_str) == 0) {
return EMH_store_error_s1(EMH_severity_error, EMH_AE_error_base, string("获取target内容异常,请检查handler:jd_get_target是否配置").c_str());;
}
//remove(file_location.str().c_str());
//char **p = (char **)malloc(sizeof(char *));
//p[0] = (char *)malloc(sizeof(char) * 10);
//p[0] = "";
//ITKCALL(PREF_set_char_values("jd2_task_target", 1, p));
//free(p);
split(target_str, ",", &target_vec);
for (int i = 0; i < target_vec.size(); i++) {
mail_content << target_vec[i].c_str();
mail_content << " ";
mail_content << paras["mail_para"];
mail_content << "\r\n";
}
POM_AM__set_application_bypass(false);
vector<string> address, to_name, from_pref;
stringstream mail_body;
tag_t owning;
char *from_user, **pref_values;
int pref_cnt, from_index = -1;
split(paras["mail_address"], ",", &address);
AOM_ask_value_tag(root_task, "owning_user", &owning);
AOM_ask_value_string(owning, "object_string", &from_user);
PREF_ask_char_values("jd2_user_mail_account", &pref_cnt, &pref_values);
printf("from_user:%s\n", from_user);
for (int i = 0; i < pref_cnt; i++) {
split(pref_values[i], ":", &from_pref);
printf("pref:%s\n", pref_values[i]);
}
if (from_pref.size() == 0) {
printf("没有找到对应用户邮箱\n");
return 0;
}
CSendMail sMailer;
sMailer.setServerName("smtp.mxhichina.com"); //邮箱smtp,如"smtp.126.com"
sMailer.setUserName("lvmh@jide.cn"); //邮箱账号名,如"****@126.com"
sMailer.setUserPwd("lmh1995815."); //邮箱密码
sMailer.setSenderName(from_user); //发件人名字
sMailer.setSenderAddress("lvmh@jide.cn"); //发送邮箱地址,填你账号的地址,上面的邮箱账号名"****@126.com"
mail_content << "\r\n";
mail_content << "from: ";
mail_content << from_user;
mail_content << "\r\n";
mail_content << "email: ";
mail_content << from_pref[1];
mail_content << "\r\n";
for (int i = 0; i < address.size(); i++) {
split(address[i], "@", &to_name);
sMailer.addReceiver(to_name[0].c_str(), address[i].c_str()); //添加邮件接收者
to_name.clear();
}
if (sMailer.Connent()) { //每次发邮件前都需要connect
if (sMailer.SendMail("SAP更改", mail_content.str().c_str())) //第一个字符串是邮件标题,第二个是邮件内容
cout << "邮件发送成功!\n";
}
return 0;
}