gpt4 book ai didi

c++ - 如何从 pjsip 发送电子邮件。是否有任何默认方法可用于发送电子邮件

转载 作者:搜寻专家 更新时间:2023-10-31 02:06:59 25 4
gpt4 key购买 nike

我有一个用于调用应用程序的 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 "princetomy12@gmail.com"
#define TO "sangeethjohn01@gmail.com"



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, "princetomy12@gmail.com");
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 的内置函数发送电子邮件。

  1. 创建了单独的项目。
  2. 将项目包含在 Visual Studio 解决方案资源管理器中。
  3. 在pjsip中包含头文件
  4. 在设备注册失败的情况下从项目中调用我的方法。

关于c++ - 如何从 pjsip 发送电子邮件。是否有任何默认方法可用于发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49449105/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com