Postman本身并不支持发送电子邮件功能,但你可以通过配置SMTP服务器来使用Postman发送带有附件的电子邮件。以下是在Debian系统上配置Postman发送邮件的步骤:
/opt/postman
。smtp.gmail.com
,端口是587
或465
。pm.test("Send email with attachment", function () {
var emailData = {
"to": "recipient@example.com",
"subject": "Test Email with Attachment",
"text": "This is a test email with an attachment.",
"attachment": [
{
"filename": "example.txt",
"content": "This is the content of the attachment."
}
]
};
var request = pm.request.url({
method: "POST",
url: "https://your-smtp-server.com/send-email",
header: {
"Content-Type": "application/json"
},
body: {
mode: "raw",
raw: JSON.stringify(emailData)
}
});
request.send();
});
recipient@example.com
替换为收件人的电子邮件地址,https://your-smtp-server.com/send-email
替换为你的SMTP服务器地址,确保它支持发送带有附件的电子邮件。请注意,具体的SMTP服务器地址和端口可能因你使用的邮件服务提供商而异。如果你使用的是Gmail,可能需要启用“允许不够安全的应用”选项,或者使用应用专用密码而不是普通的Gmail密码。