【网络通信】10分钟教会你如何配置Lwip中的Smtp功能

💌 所属专栏:【网络通信】
😀 作  者:兰舟比特 🐾
🚀 个人简介:热爱开源系统与嵌入式技术,专注 Linux、网络通信、编程技巧、面试总结与软件工具分享,持续输出实用干货!
💡 欢迎大家:这里是兰舟比特的技术小站,喜欢的话请点赞、收藏、评论三连击!有问题欢迎留言交流😘😘😘


本篇博客主要介绍的Lwip中的Smtp功能,以及如何配置使用和有哪些需要注意的地方,希望对你有帮助。


一、📦 什么是 LwipSmtp?

LwipSmtp 是一个基于 LwIP(Lightweight IP)协议栈 的轻量级 SMTP 客户端库,专为嵌入式系统设计,用于在资源受限的设备上实现通过以太网或 Wi-Fi 发送电子邮件的功能。

它通常用于如 STM32、ESP32 等嵌入式平台,结合 LwIP 实现联网功能后,可让设备主动发送邮件通知、报警信息、日志报告等。


二、🔧 主要功能

  • ✅ 支持标准 SMTP 协议
  • ✅ 支持加密连接(SSL/TLS)
  • ✅ 可设置邮件主题、正文、收件人等
  • ✅ 支持附件发送(视具体实现而定)
  • ✅ 轻量高效,适合嵌入式系统使用
  • ✅ 提供回调函数机制处理发送状态

三、📌 典型应用场景

  • 工业监控系统:设备故障自动发送邮件报警
  • 智能家居:发送状态变更通知
  • 远程数据采集:定时发送数据报告
  • 嵌入式日志系统:异常时发送错误日志

四、🧩 使用流程(伪代码)

// 初始化 LwIP 栈
lwip_init();

// 设置 SMTP 服务器域名
smtp_set_server_addr("smtp.example.com");

// 设置Smtp服务用户名和smtp服务器密码
smtp_set_auth("user@example.com", "your_password_or_token");

// 设置发件人、收件人、主题、内容
smtp_mailto("from@example.com", "to@example.com");
smtp_set_subject("System Alert");
smtp_set_body("This is an alert from your embedded device.");

// 发送邮件
smtp_send();

五、 📚 注意事项

> 1.编译库以及使用时需要lwipopts.h中包含以下三个宏定义。 			
> #define LWIP_ALTCP                      1
> #define LWIP_ALTCP_TLS                  1
> #define LWIP_DNS                        1
2.如果使用的是163等之类的邮箱(如下图)
> 登录163邮箱网页版 (mail.163.com)
> 点击右上角"设置" -> "POP3/SMTP/IMAP"
> 开启"SMTP服务"
> 按提示设置授权码(通常是16位字符)
> 替换上面的smtp服务器密码

此图是163网站打开smtp服务的截图


📎 特点总结

特性描述
轻量级内存占用低,适合嵌入式平台
易集成接口简单,易于移植到不同平台
功能完整支持基本邮件发送功能
可扩展可自行添加附件、HTML 内容等功能

💡 注意事项

  • 使用前需确保 LwIP 网络栈已正确初始化并联网。
  • 若使用 Gmail、QQ邮箱等服务,需开启 SMTP 并获取授权码。
  • 加密支持(TLS/SSL)可能需要额外的库(如 mbedTLS)配合使用。

版权声明:

本文为 兰舟比特 原创内容,如需转载,请注明出处及作者,禁止未经授权的引用或商用。

INTRODUCTION lwIP is a small independent implementation of the TCP/IP protocol suite. The focus of the lwIP TCP/IP implementation is to reduce the RAM usage while still having a full scale TCP. This making lwIP suitable for use in embedded systems with tens of kilobytes of free RAM and room for around 40 kilobytes of code ROM. lwIP was originally developed by Adam Dunkels at the Computer and Networks Architectures (CNA) lab at the Swedish Institute of Computer Science (SICS) and is now developed and maintained by a worldwide network of developers. FEATURES * IP (Internet Protocol, IPv4 and IPv6) including packet forwarding over multiple network interfaces * ICMP (Internet Control Message Protocol) for network maintenance and debugging * IGMP (Internet Group Management Protocol) for multicast traffic management * MLD (Multicast listener discovery for IPv6). Aims to be compliant with RFC 2710. No support for MLDv2 * ND (Neighbor discovery and stateless address autoconfiguration for IPv6). Aims to be compliant with RFC 4861 (Neighbor discovery) and RFC 4862 (Address autoconfiguration) * DHCP, AutoIP/APIPA (Zeroconf), ACD (Address Conflict Detection) and (stateless) DHCPv6 * UDP (User Datagram Protocol) including experimental UDP-lite extensions * TCP (Transmission Control Protocol) with congestion control, RTT estimation fast recovery/fast retransmit and sending SACKs * raw/native API for enhanced performance * Optional Berkeley-like socket API * TLS: optional layered TCP ("altcp") for nearly transparent TLS for any TCP-based protocol (ported to mbedTLS) (see changelog for more info) * PPPoS and PPPoE (Point-to-point protocol over Serial/Ethernet) * DNS (Domain name resolver incl. mDNS) * 6LoWPAN (via IEEE 802.15.4, BLE or ZEP) APPLICATIONS * HTTP server with SSI and CGI (HTTPS via altcp) * SNMPv2c agent with MIB compiler (Simple Network Management Protocol), v3 via altcp * SNTP (Simple network time protocol) * NetBIOS name service responder * MDNS (Multicast DNS) responder * iPerf server implementation * MQTT client (TLS support via altcp) LICENSE lwIP is freely available under a BSD license. DEVELOPMENT lwIP has grown into an excellent TCP/IP stack for embedded devices, and developers using the stack often submit bug fixes, improvements, and additions to the stack to further increase its usefulness. Development of lwIP is hosted on Savannah, a central point for software development, maintenance and distribution. Everyone can help improve lwIP by use of Savannah's interface, Git and the mailing list. A core team of developers will commit changes to the Git source tree. The lwIP TCP/IP stack is maintained in the 'lwip' Git module and contributions (such as platform ports) are in the 'contrib' Git module. See doc/savannah.txt for details on Git server access for users and developers. The current Git trees are web-browsable: http://git.savannah.gnu.org/cgit/lwip.git http://git.savannah.gnu.org/cgit/lwip/lwip-contrib.git Submit patches and bugs via the lwIP project page: http://savannah.nongnu.org/projects/lwip/ Continuous integration builds (GCC, clang): https://travis-ci.org/lwip-tcpip/lwip DOCUMENTATION Self documentation of the source code is regularly extracted from the current Git sources and is available from this web page: http://www.nongnu.org/lwip/ Also, there are mailing lists you can subscribe at http://savannah.nongnu.org/mail/?group=lwip plus searchable archives: http://lists.nongnu.org/archive/html/lwip-users/ http://lists.nongnu.org/archive/html/lwip-devel/ There is a wiki about lwIP at http://lwip.wikia.com/wiki/LwIP_Wiki You might get questions answered there, but unfortunately, it is not as well maintained as it should be. lwIP was originally written by Adam Dunkels: http://dunkels.com/adam/ Reading Adam's papers, the files in docs/, browsing the source code documentation and browsing the mailing list archives is a good way to become familiar with the design of lwIP. Adam Dunkels Leon Woestenberg
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

兰舟比特

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值