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密碼。