我有一个用于 call 应用程序的pjsip项目。我有一个外部文件(例如curl)。是否可以向pjsip应用程序添加外部程序包,或者如何向pjsip添加外部程序包。是否有任何默认方法可用于发送电子邮件。我想检查的东西。请帮助解决我的问题。谢谢。
设备注册失败时,我想从pjsip发送电子邮件。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <curl/curl.h>
using namespace std;
#define CURL_STATICLIB
#define FROM "[email protected]"
#define TO "[email protected]"
static const char *payload_text[] = {
"To: " TO "\r\n",
"From: " FROM "\r\n",
"Subject: SMTP TLS example message\r\n",
NULL
};
struct upload_status {
int lines_read;
};
static size_t payload_source(void *ptr, size_t size, size_t nmemb, void *userp)
{
struct upload_status *upload_ctx = (struct upload_status *)userp;
const char *data;
if ((size == 0) || (nmemb == 0) || ((size*nmemb) < 1)) {
return 0;
}
data = payload_text[upload_ctx->lines_read];
if (data) {
size_t len = strlen(data);
memcpy(ptr, data, len);
upload_ctx->lines_read++;
return len;
}
return 0;
}
int main(void)
{
system("pause");
//return (int)res;
}
static int call_send_email()
{
CURL *curl;
CURLcode res = CURLE_OK;
struct curl_slist *recipients = NULL;
struct upload_status upload_ctx;
upload_ctx.lines_read = 0;
cout << "\nstart pgm";
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_USERNAME, "[email protected]");
curl_easy_setopt(curl, CURLOPT_PASSWORD, "********");
curl_easy_setopt(curl, CURLOPT_URL, "smtp://smtp.gmail.com:587");
curl_easy_setopt(curl, CURLOPT_USE_SSL, (long)CURLUSESSL_ALL);
curl_easy_setopt(curl, CURLOPT_CAINFO, "google.pem");
curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM);
recipients = curl_slist_append(recipients, TO);
//curl_easy_setopt(curl, CURLOPT_FILE, "edgE0DF.tmp");
curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);
curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
cout << "check status";
if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_slist_free_all(recipients);
curl_easy_cleanup(curl);
}
cout << "completed execution";
return 1;
}
最佳答案
我为电子邮件发送创建了单独的项目,并将该项目包含在pjsip项目中。即我已经包括头文件,并从pjsip中的设备注册失败案例中调用了我的函数。我认为这种解决方案更好。我认为没有其他选择可以使用来自pjsip的内置函数发送电子邮件。
关于c++ - 如何从pjsip发送电子邮件。是否有任何默认方法可用于发送电子邮件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49449105/