如何解决使用来自经典 asp 的附件向 mailgun 发送电子邮件
我正在尝试从经典 asp 中获取一个旧应用程序,以通过 mailgun api 发送电子邮件。我可以将它发送到将发送不带附件的常规电子邮件的位置,但是当我尝试将其作为多部分/表单数据发送时,它无法正常工作。它出错了,没有详细的错误响应。
Function SendMailSync(toAddress,fromAddress,subject,body,htmlBody,attachment)
Dim httpPostData
Dim mailGunMessageUrl
Const MAILGUN_BASE_URL = "https://api.mailgun.net/v3/www.domain.com"
Const MAILGUN_API_KEY = "myapikey"
httpPostData = "from=" & fromAddress
httpPostData = httpPostData & "&to=" & toAddress
httpPostData = httpPostData & "&subject=" & subject
httpPostData = httpPostData & "&text=" & body
httpPostData = httpPostData & "&html=" & htmlBody
if attachment <> "" then
httpPostData = httpPostData & "&attachment=" & attachment
end if
sBoundary = String(6,"-") & Replace(Mid(CreateObject("Scriptlet.TypeLib").GUID,2,36),"-","")
set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
mailGunMessageUrl = MAILGUN_BASE_URL & "/messages"
http.Open "POST",mailGunMessageUrl,false,"api",MAILGUN_API_KEY
http.setRequestHeader "Content-Type","multipart/form-data; boundary=" & sBoundary
http.setRequestHeader "Authorization","Basic AUTH_STRING"
http.Send httpPostdata
If http.status <> 200 Then
Response.Write "An error occurred: " & http.responseText
End If
SendMailSync = http.responseText
Set http = nothing
End Function
Function SendMailSync(toAddress,htmlBody)
Dim httpPostData
Dim mailGunMessageUrl
Const MAILGUN_BASE_URL = "https://api.mailgun.net/v3/www.domain.com"
Const MAILGUN_API_KEY = "myapikey"
httpPostData = "from=" & fromAddress
httpPostData = httpPostData & "&to=" & toAddress
httpPostData = httpPostData & "&subject=" & subject
httpPostData = httpPostData & "&text=" & body
httpPostData = httpPostData & "&html=" & htmlBody
set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
mailGunMessageUrl = MAILGUN_BASE_URL & "/messages"
http.Open "POST","application/x-www-form-urlencoded"
http.setRequestHeader "Authorization","Basic AUTH_STRING"
http.Send httpPostdata
If http.status <> 200 Then
Response.Write "An error occurred: " & http.responseText
End If
SendMailSync = http.responseText
Set http = nothing
End Function
有没有人看到我还需要调整什么才能发送多部分/表单数据。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。