Postman本身不支持直接发送邮件,但可通过配置SMTP服务器或结合脚本/工具实现发件人邮箱的设置与邮件发送。以下是针对Debian系统的具体步骤:
安装Postman
从Postman官网下载Debian版本安装包(.deb格式),通过以下命令安装:
wget https://dl.pstmn.io/download/latest/linux64 -O postman.deb
sudo dpkg -i postman.deb
明确发件人邮箱信息
准备好发件人邮箱地址(如your-email@gmail.com)、SMTP服务器地址(如Gmail为smtp.gmail.com)、端口(如Gmail的587或465)、用户名(发件人邮箱前缀)及密码(或应用专用密码,如Gmail需开启“允许不够安全的应用”或生成应用密码)。
打开Postman设置
点击左上角头像→选择“Settings”(设置)→进入“General”(常规) tab。
配置Email参数
在“Email” section中,找到“Send email using”下拉菜单,选择“SMTP”;依次填写以下信息:
smtp.gmail.com(Gmail)、smtp.office365.com(Outlook);your-email);保存设置
点击“Save”按钮,完成SMTP服务器配置。
若需更灵活的邮件控制(如群发、HTML格式),可通过Python脚本结合Postman调用实现:
pip install smtplib email
send_email.py)import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email(to_email, subject, body):
# 发件人配置
sender_email = "your-email@example.com"
sender_password = "your-password" # 或应用专用密码
# 创建邮件对象
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = to_email
msg['Subject'] = subject
# 添加邮件正文
msg.attach(MIMEText(body, 'plain'))
# 连接SMTP服务器并发送
try:
server = smtplib.SMTP('smtp.example.com', 587) # 替换为你的SMTP服务器和端口
server.starttls() # 启用TLS加密
server.login(sender_email, sender_password)
server.sendmail(sender_email, to_email, msg.as_string())
server.quit()
print("Email sent successfully!")
except Exception as e:
print(f"Failed to send email: {e}")
# 示例调用(可通过Postman传递参数)
if __name__ == "__main__":
import sys
to_email = sys.argv[1] if len(sys.argv) > 1 else "recipient@example.com"
subject = sys.argv[2] if len(sys.argv) > 2 else "Test Email"
body = sys.argv[3] if len(sys.argv) > 3 else "This is a test email from Debian."
send_email(to_email, subject, body)
http://localhost:5000/send-email,需将脚本部署为Web服务,或直接通过Command模块调用本地脚本);{
"to_email": "recipient@example.com",
"subject": "Test Email from Postman",
"body": "This email is sent via Postman and Python script."
}
dotenv)管理敏感信息;mailx等命令行工具,需提前安装(sudo apt install mailutils)并配置/etc/mail.rc文件。