c++ cgi执行shell命令l发送qq邮件mailx

2021/5/17 7:26:01

本文主要是介绍c++ cgi执行shell命令l发送qq邮件mailx,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

#include <cstdlib> //随机数 
#include <iostream>
#include <cstdio> //popen函数调用的需要 
#include <string>
#include <sstream>    //用于整型转字符串 
using namespace std;
int main(){
    
    cout << "Content-type:text/html\n\n";
    srand(time(0));
    int rand=(random()%(99999 - 10000 +1)) + 10000;
    stringstream str_r;
    str_r << rand;
    string str_rand=str_r.str();    //随机数 
    
    string a="echo 'Dear users, your verification code is "+str_rand+" , this verification code is valid in 10 minutes. Thank you for using ' | mail -s 'bin of web'  1926804226@qq.com";
    //cout<<a;
//    FILE *fp=popen(a.c_str(),"r");
//    if(!fp) return 1;
//    pclose(fp);
    cout<<system(a.c_str());    //返回0 为成功
    return 0;
} 

 

g++ -o text.cgi text.cpp

mail 命令不是root命令,非root也可以调用

由于我的证书在root下,apache没有权限访问(/root 其他用户没有读的权限)

所以可以将证书移到apache权限目录或者重新生成证书,修改/etc/mail.rc 文件的证书路径,不用重启如何服务,即可成功

权限,yyds

 

 

 

 

 

 

 

参考:

linux mailx 发送邮件到qq邮箱:https://www.cnblogs.com/CloudComputing-binbin/p/14761645.html

c++ 执行shell命令:https://blog.csdn.net/u012234115/article/details/89215980

linux 非root用户mailx发送邮件:https://www.cnblogs.com/hydd/p/14338536.html

 



这篇关于c++ cgi执行shell命令l发送qq邮件mailx的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程