当前位置: 首页 > news >正文

做网站用cms好吗合肥疫情最新消息

做网站用cms好吗,合肥疫情最新消息,株洲手机网站建设,河南省建设局网站首页实验目的 运用各种编程语言实现基于 smtp 协议的 Email 客户端软件。 实验内容 1. 选择合适的编程语言编程实现基于 smtp 协议的 Email 客户端软件。 2. 安装 Email 服务器或选择已有的 Email 服务器,验证自己的 Email 客户端软件是否能进行正常的 Email 收发功…

实验目的

运用各种编程语言实现基于 smtp 协议的 Email 客户端软件。

实验内容

1. 选择合适的编程语言编程实现基于 smtp 协议的 Email 客户端软件。

2. 安装 Email 服务器或选择已有的 Email 服务器,验证自己的 Email 客户端软件是否能进行正常的 Email 收发功能。

实验过程

使用学校地的SMTP服务器做发送,这里操作比较简单,无需授权码,直接使用账号密码登录即可

编写基于smtp的邮件发送客户端,这里调用了Curl库来实现,这个库支持多种通信协议

编写基于pop3的邮件接收客户端(在查询相关资料后,pop3相较于smtp更常用于邮件接收,此处选择pop3来实现更贴近实际情况)

关键代码讲解

smtp邮件发送客户端,主要邮件发送函数,使用了 libcurl 库。首先初始化一个 CURL 句柄,然后设置 SMTP 服务器的地址、发送者的电子邮件地址和密码。接着,函数设置邮件的接收者,构造邮件的内容。函数调用 curl_easy_perform 函数来发送邮件,如果发送失败,会打印出错误信息。最后,函数清理并释放所有使用过的资源。

void sendEmail(  const std::string& smtpServer,   const std::string& from,   const std::vector<std::string>& to,   const std::string& password,   const std::string& subject,   const std::string& body  
) {  CURL *curl;  CURLcode res = CURLE_OK;  struct curl_slist *recipients = NULL;  curl = curl_easy_init();  if(curl) {  curl_easy_setopt(curl, CURLOPT_USERNAME, from.c_str());  curl_easy_setopt(curl, CURLOPT_PASSWORD, password.c_str());  curl_easy_setopt(curl, CURLOPT_URL, smtpServer.c_str());  curl_easy_setopt(curl, CURLOPT_MAIL_FROM, from.c_str());  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);  curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);  for(const auto& recipient : to) {  recipients = curl_slist_append(recipients, recipient.c_str());  }  curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);  std::string email = "To: " + to[0] + "\r\n" +  "From: " + from + "\r\n" +  "Subject: " + subject + "\r\n\r\n" +  body;  curl_easy_setopt(curl, CURLOPT_READFUNCTION, payload_source);  curl_easy_setopt(curl, CURLOPT_READDATA, &email);  res = curl_easy_perform(curl);  if(res != CURLE_OK)  std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;  curl_slist_free_all(recipients);  curl_easy_cleanup(curl);  }  
}  

pop3邮件接收客户端,也是使用libcurl的库进行连接,接收用户名和密码通过pop3方式登录,返回邮件列表

void receiveEmail(const std::string& pop3Server, const std::string& username, const std::string& password) {CURL *curl;CURLcode res = CURLE_OK;curl = curl_easy_init();if(curl) {curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);curl_easy_setopt(curl, CURLOPT_USERNAME, username.c_str());curl_easy_setopt(curl, CURLOPT_PASSWORD, password.c_str());curl_easy_setopt(curl, CURLOPT_URL, pop3Server.c_str());curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL);std::string response;curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);res = curl_easy_perform(curl);if(res != CURLE_OK)std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;elsestd::cout << response << std::endl;curl_easy_cleanup(curl);}
}

运行示例

编译运行smtp邮件客户端发送邮件

用户输入信息:发送方邮箱地址/发送方邮箱授权码/接收方邮箱地址/邮件主题/邮件内容,显示发送过程中的日志信息

  • 邮件接受效果(此处示例为群发两封邮件)

POP3客户端接收邮件用户输入信息登录,然后列出所有的邮件

相关代码

BJTU_CS_Learning/computernetwork at main · JJLi0427/BJTU_CS_Learning (github.com)

http://www.tj-hxxt.cn/news/56775.html

相关文章:

  • 做网站获取手机号码网站排名优化客服
  • 制作页培训大连百度seo
  • 相册制作模板平台优化是什么意思
  • 四川煤矿标准化建设网站免费大数据平台
  • 大学生毕业论文管理系统入口湘潭seo公司
  • 做dm素材网站百度快照有什么用
  • 网站开发毕设任务书百度快照优化推广
  • 视频如何上传到wordpress太原百度网站快速优化
  • 做自己移动端网站怎么优化关键词
  • 网站建站企业网络推广包括哪些
  • 常见的三种网站类型seo外链推广工具下载
  • 网站集约化建设 技术越秀seo搜索引擎优化
  • 中装建设信息流优化师
  • wordpress做出影视网站站长工具ping检测
  • 沈阳网站建设公司怎么样爱站网
  • 长沙网站快速优化排名搜索引擎优化到底是优化什么
  • 合肥做百度网站电影站的seo
  • 免费做图网站衡阳seo快速排名
  • 哪个网站容易做二级域名南京网站制作
  • 网站速度提升什么软件可以排名次
  • 做网站的收费标准网站seo排名优化软件
  • 企业网站建设的常见流程西地那非片
  • 镇江建工建设集团网站百度一下你就知道官网首页
  • wordpress微信付款郑州seo竞价
  • wordpress去谷歌插件河南智能seo快速排名软件
  • 做山西杂粮的网站优化大师官网
  • 做销售用什么网站国外独立站网站
  • 中华住房与城乡建设厅网站网站注册搜索引擎的目的是
  • 网站 服务器 虚拟主机seo网站优化价格
  • 福州做网站建设服务商网站域名怎么注册