-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from WKJay/develop
增加附件功能
- Loading branch information
Showing
6 changed files
with
453 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,71 +12,90 @@ | |
Date: 2019-10-14 | ||
Author: wangjunjie | ||
Modify: 添加多收件人功能 | ||
3. Version: V1.0.2 | ||
Date: 2020-06-22 | ||
Author: WKJay | ||
Modify: 增加附件功能 | ||
*************************************************/ | ||
#include "smtp_client.h" | ||
#include "rtthread.h" | ||
|
||
//若使用TLS加密则需要更大的堆栈空间 | ||
#ifdef SMTP_CLIENT_USING_TLS | ||
#define SMTP_CLIENT_THREAD_STACK_SIZE 4096 | ||
#define SMTP_CLIENT_THREAD_STACK_SIZE 8192 | ||
#else | ||
#define SMTP_CLIENT_THREAD_STACK_SIZE 2048 | ||
#define SMTP_CLIENT_THREAD_STACK_SIZE 4096 | ||
#endif | ||
|
||
#define DBG_ENABLE | ||
#define DBG_LEVEL 3 | ||
#define DBG_COLOR | ||
#define DBG_SECTION_NAME "SMTP_EXAMPLE" | ||
#include "rtdbg.h" | ||
|
||
/* | ||
*邮件信息相关宏定义 | ||
*/ | ||
//smtp 服务器域名 | ||
#define SMTP_SERVER_ADDR "smtp.qq.com" | ||
#define SMTP_SERVER_ADDR "smtp.163.com" | ||
//smtp 服务器端口号 | ||
#define SMTP_SERVER_PORT "25" | ||
//smtp 登录用户名 | ||
#define SMTP_USERNAME "" | ||
#define SMTP_USERNAME "" | ||
//smtp 登录密码(或凭证) | ||
#define SMTP_PASSWORD "" | ||
#define SMTP_PASSWORD "" | ||
//邮件主题 | ||
#define SMTP_SUBJECT "SMTP TEST" | ||
|
||
#define SMTP_SUBJECT "SMTP TEST" | ||
|
||
//邮件内容 | ||
char *content = "THIS IS SMTP TEST\r\n" | ||
"HELLO SMTP\r\n" | ||
"--------------------------------------\r\n" | ||
"based on ---> RT-Thread\r\n" | ||
"based on ---> SMTP_CLIENT\r\n"; | ||
|
||
|
||
uint8_t send_enable = 0; | ||
|
||
void smtp_thread(void *param) | ||
{ | ||
//手动延时等待网络初始化成功 | ||
rt_thread_delay(10000); | ||
|
||
//初始化smtp客户端 | ||
smtp_client_init(); | ||
//设置服务器地址 | ||
smtp_set_server_addr(SMTP_SERVER_ADDR, ADDRESS_TYPE_DOMAIN, SMTP_SERVER_PORT); | ||
//设置服务器认证信息 | ||
smtp_set_auth(SMTP_USERNAME, SMTP_PASSWORD); | ||
|
||
//添加收件人1 | ||
smtp_add_receiver("[email protected]"); | ||
//添加收件人2 | ||
smtp_add_receiver("[email protected]"); | ||
//添加收件人3 | ||
smtp_add_receiver("[email protected]"); | ||
//删除收件人2 | ||
smtp_delete_receiver("[email protected]"); | ||
smtp_add_receiver("[email protected]"); | ||
|
||
//发送邮件 | ||
rt_kprintf("\r\n[smtp]: O > start to send mail\r\n"); | ||
if (smtp_send_mail(SMTP_SUBJECT, content) == 0) | ||
{ | ||
//发送成功 | ||
rt_kprintf("\r\n[smtp]: O > send mail success!\r\n"); | ||
} | ||
else | ||
while (1) | ||
{ | ||
//发送失败 | ||
rt_kprintf("\r\n[smtp]: X > send mail fail!\r\n"); | ||
if (send_enable) | ||
{ | ||
smtp_add_attachment("/a.txt", "a.txt"); | ||
smtp_add_attachment("/b.txt", "b.txt"); | ||
//发送邮件 | ||
LOG_D("start to send mail"); | ||
if (smtp_send_mail(SMTP_SUBJECT, content) == 0) | ||
{ | ||
//发送成功 | ||
LOG_I("send mail success!"); | ||
} | ||
else | ||
{ | ||
//发送失败 | ||
LOG_E("send mail fail!"); | ||
} | ||
//清除附件 | ||
smtp_clear_attachments(); | ||
//防止频繁发送 | ||
rt_thread_mdelay(30000); | ||
send_enable = 0; | ||
} | ||
else | ||
{ | ||
rt_thread_mdelay(500); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -92,3 +111,11 @@ int smtp_thread_entry(void) | |
return RT_EOK; | ||
} | ||
INIT_APP_EXPORT(smtp_thread_entry); | ||
|
||
int smtp_test(uint8_t argc, char *argv[]) | ||
{ | ||
send_enable = 1; | ||
return 0; | ||
} | ||
MSH_CMD_EXPORT(smtp_test, smtp test); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.