微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用来自经典 asp 的附件向 mailgun 发送电子邮件

如何解决使用来自经典 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?