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.
154 lines
5.0 KiB
154 lines
5.0 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[2000];
|
|
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);
|
|
|
|
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";
|
|
}
|
|
//tag_t win;
|
|
//BOM_create_window(&win);
|
|
//for (int i = 0;i < att_cnt;i++) {
|
|
// if (isTypeOf(attachments[i], "Form")) {
|
|
// int rel_cnt, *levels;
|
|
// tag_t *rels, rev = NULLTAG, form;
|
|
// char **relations;
|
|
// form = attachments[i];
|
|
// WSOM_where_referenced2(form, 1, &rel_cnt, &levels, &rels, &relations);
|
|
// for (int j = 0;j < rel_cnt;j++) {
|
|
// printf("relations:%s\n", relations[j]);
|
|
// if (tc_strcmp(relations[j], "IMAN_master_form") == 0) {
|
|
// rev = rels[j];
|
|
// }
|
|
// }
|
|
// if (rev == NULLTAG) {
|
|
// printf("revision get error\n");
|
|
// continue;
|
|
// }
|
|
// char *item_id;
|
|
// AOM_ask_value_string(rev, "item_id", &item_id);
|
|
|
|
// char *rev_id;
|
|
// AOM_ask_value_string(rev, "item_revision_id", &rev_id);
|
|
// mail_content << item_id;
|
|
// mail_content << "/";
|
|
// mail_content << rev_id;
|
|
// mail_content << " ";
|
|
// mail_content << paras["mail_para"];
|
|
// mail_content << "\r\n";
|
|
// } else if (isTypeOf(attachments[i], "PSBOMViewRevision")) {
|
|
// tag_t top_line, rev;
|
|
// char *id;
|
|
// BOM_set_window_top_line_bvr(win, attachments[i], &top_line);
|
|
// if (top_line == NULLTAG)
|
|
// continue;
|
|
// AOM_ask_value_tag(top_line, "bl_line_object", &rev);
|
|
// if (rev == NULLTAG)
|
|
// continue;
|
|
// AOM_ask_value_string(rev, "item_id", &id);
|
|
|
|
// char *rev_id;
|
|
// AOM_ask_value_string(rev, "item_revision_id", &rev_id);
|
|
// mail_content << id;
|
|
// mail_content << "/";
|
|
// mail_content << rev_id;
|
|
// mail_content << " ";
|
|
// mail_content << paras["mail_para"];
|
|
// mail_content << "\r\n";
|
|
// }
|
|
//}
|
|
//BOM_close_window(win);
|
|
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 (tc_strcmp(from_user, from_pref[0].c_str()) == 0) {
|
|
// break;
|
|
//}
|
|
//from_pref.clear();
|
|
}
|
|
|
|
if (from_pref.size() == 0) {
|
|
printf("没有找到对应用户邮箱\n");
|
|
return 0;
|
|
}
|
|
|
|
CSendMail sMailer;
|
|
// freopen("F://mailfile//out.txt","w+",stdout);
|
|
|
|
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;
|
|
} |