首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >启用邮件的API AJAX调用

启用邮件的API AJAX调用
EN

Stack Overflow用户
提问于 2013-11-30 23:30:58
回答 1查看 493关注 0票数 0

我正在尝试了解MailEnable应用程序接口是如何工作的。到目前为止,我只能查看AJAX文档并让LOGIN命令工作。就像这样:

代码语言:javascript
复制
AJAXRequest('LOGIN','Username='user'&Password='pass', false);

该命令返回如下所示的xml字符串

代码语言:javascript
复制
<BASEELEMENT SCHEMA="VALUE" METHOD="LOGIN"><RETURNVALUE>1</RETURNVALUE></BASEELEMENT>

如果运行正常,除了LOGIN命令(例如注销或列表消息)之外的任何其他命令都会给我一个超时错误,如下所示

代码语言:javascript
复制
<BASEELEMENT SCHEMA="TIMEOUT" METHOD="LOGOUT"></BASEELEMENT>

我用来注销和列表消息的命令就是这些,它们都给了我下面的错误。

代码语言:javascript
复制
AJAXRequest('LIST-MESSAGES','Folder=/Inbox', false);
AJAXRequest('LOG-OFF','ID=', false);

我使用的是that链接中的示例文件。我只是不能理解我是否遗漏了什么,或者这些示例和文档不是最新的,或者有问题或smth?

谢谢!

(我找不到"mailenable“标签来标记这个问题。很遗憾在stackoverflow中没有人标记过mailenable,mailenable论坛就像一座坟墓:S)

EN

回答 1

Stack Overflow用户

发布于 2014-11-04 13:03:09

好的,根据评论,我正在为MailEnable发布一个自写的邮件Api

代码语言:javascript
复制
Imports System
Imports System.Web
Imports MailEnable.Administration
Imports QueryStringModule
Imports System.Xml

Public Class MailApi : Implements IHttpHandler

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
    Get
        Return False
    End Get
End Property

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim doc As XmlDocument = GetXmlToShow(context)

    context.Response.ContentType = "test/xml"

    context.Response.ContentEncoding = System.Text.Encoding.UTF32 
    context.Response.Expires = -1
    context.Response.Cache.SetAllowResponseInBrowserHistory(True)

    doc.Save(context.Response.Output)

End Sub

Private Function GetXmlToShow(context As HttpContext) As XmlDocument
    Dim Result As String = ""
    Dim doc As New XmlDocument

    Try
        Dim query As String = QueryStringModule.Decrypt(context.Request.QueryString("val").Replace(" ", "+"))

        Dim PostOffice As String = HttpUtility.ParseQueryString(query).Get("PostOffice")
        Dim Domain As String = HttpUtility.ParseQueryString(query).Get("Domain")
        Dim Username As String = HttpUtility.ParseQueryString(query).Get("Username")
        Dim Password As String = HttpUtility.ParseQueryString(query).Get("Password")
        Dim MailBoxQuota As Integer = CInt(Val(HttpUtility.ParseQueryString(query).Get("MailBoxQuota")))
        If MailBoxQuota = 0 Then
            MailBoxQuota = 102400
        End If

        Dim act As String = HttpUtility.ParseQueryString(query).Get("Action")

        Select Case act
            Case "Create"
                Result = fnCreateMailAccount(Username, PostOffice)
            Case "Delete"

            Case "Update"

            Case "GetAll"
                Result = fnGetAll(Username, PostOffice)
            Case "GetToday"

            Case "GetFromTo"

            Case "GetUnread"
                Result=fnGetUnread(Username,PostOffice)
            Case "GetRead"

            Case "GetUnreadCount"
                Result = fnGetUnreadCount(Username, PostOffice)
            Case "GetTotalCount"
                Result = fnGetTotalCount(Username, PostOffice)
            Case Else
                Result = "<result status=""Err""><reason>Invaid action!</reason></result>"
        End Select

        doc.LoadXml(Result)
    Catch ex As Exception
        Result = "<result status=""Err""><reason>" + ex.Message + "</reason></result>"
        doc.LoadXml(Result)
    End Try
    Return doc 
End Function

Private Function fnGetUnread(Username As String, Postoffice As String) As String
    Dim XMLFile As String = ""
    Try
        If Len(Username) <= 0 Or Len(Postoffice) <= 0 Then
            Throw New ArgumentException("Invalid Parameters!")
        Else
            Dim oMailbox As New MailEnable.Administration.Mailbox
            oMailbox.Postoffice = Postoffice
            oMailbox.MailboxName = Username
            oMailbox.Status = 1

            If oMailbox.GetMailbox() = 1 Then
                Dim APIResult As Long
                Dim oStore As New MailEnable.Store
                APIResult = oStore.StoreFolder_Open(Postoffice, Username, "\Inbox", 0, 1)
                If oStore.StoreFolder_FindFirstItem() = 1 Then
                    Do
                        If oStore.StoreItem_GetProperty("PR_ME_READ").ToString = "0" Or oStore.StoreItem_GetProperty("PR_ME_READ").ToString = "" Then

                            Dim WrapperStart As String = "<message>"

                            Dim ItemId As String = "<itemid>" + oStore.StoreItem_GetProperty("ME_ITEM_ID").ToString + "</itemid>"
                            Dim MessageDate As String = "<dated>" + Left(oStore.StoreItem_GetProperty("PR_ME_MESSAGEDATE").ToString, 10) + " " + Right(oStore.StoreItem_GetProperty("PR_ME_MESSAGEDATE").ToString, 8) + "</dated>"
                            Dim Attachments As String = "<attachments>" + oStore.StoreItem_GetProperty("PR_ME_ATTACHMENTS").ToString + "</attachments>"
                            Dim From As String = "<from>" + oStore.StoreItem_GetProperty("PR_ME_FROM").ToString.Replace("<", """").Replace(">", """") + "</from>"
                            Dim Subject As String = "<subject>" + oStore.StoreItem_GetProperty("PR_SUBJECT").Replace("<", """").Replace(">", """").ToString + "</subject>"
                            Dim Size As String = "<size>" + oStore.StoreItem_GetProperty("PR_ME_SIZE").ToString + "</size>"
                            Dim Status As String = "<status>" + oStore.StoreItem_GetProperty("PR_ME_FLAGSTATUS").ToString + "</status>"

                            Dim WrapperEnd As String = "</message>"

                            XMLFile = XMLFile + WrapperStart +ItemId + MessageDate + Attachments + From + Subject + Size + Status + WrapperEnd
                        End If
                    Loop While (oStore.StoreFolder_FindNextItem() = 1)
                    XMLFile = "<messages>" + XMLFile + "</messages>"
                End If
                APIResult = oStore.StoreFolder_FindClose()
                APIResult = oStore.StoreFolder_Close()
            Else
                Throw New ArgumentException("Invalid Mailbox!")
            End If
        End If
        XMLFile = "<result status=""Success"">" + XMLFile + "</result>"
    Catch ex As Exception
        XMLFile = "<result status=""Err""><reason>" + ex.Message + "</reason></result>"
    End Try
    Return XMLFile
End Function

Private Function fnGetAll(Username As String, Postoffice As String) As String
    Dim XMLFile As String = ""
    Try
        If Len(Username) <= 0 Or Len(Postoffice) <= 0 Then
            Throw New ArgumentException("Invalid Parameters!")
        Else
            Dim oMailbox As New MailEnable.Administration.Mailbox
            oMailbox.Postoffice = Postoffice
            oMailbox.MailboxName = Username
            oMailbox.Status = 1

            If oMailbox.GetMailbox() = 1 Then
                Dim APIResult As Long
                Dim oStore As New MailEnable.Store
                APIResult = oStore.StoreFolder_Open(Postoffice, Username, "\Sent Items", 0, 1)
                If oStore.StoreFolder_FindFirstItem() = 1 Then
                    Do
                        Dim WrapperStart As String = "<message>"

                        Dim ItemId As String="<itemid>"+oStore.StoreItem_GetProperty("ME_ITEM_ID").ToString +"</itemid>"
                        Dim MessageDate As String = "<dated>" + Left(oStore.StoreItem_GetProperty("PR_ME_MESSAGEDATE").ToString, 10) + " " + Right(oStore.StoreItem_GetProperty("PR_ME_MESSAGEDATE").ToString, 8) + "</dated>"
                        Dim Attachments As String = "<attachments>" + oStore.StoreItem_GetProperty("PR_ME_ATTACHMENTS").ToString + "</attachments>"
                        Dim From As String = "<from>" + oStore.StoreItem_GetProperty("PR_ME_FROM").ToString.Replace("<", """").Replace(">", """") + "</from>"
                        Dim Subject As String = "<subject>" + oStore.StoreItem_GetProperty("PR_SUBJECT").Replace("<", """").Replace(">", """").ToString + "</subject>"
                        Dim Size As String = "<size>" + oStore.StoreItem_GetProperty("PR_ME_SIZE").ToString + "</size>"
                        Dim Status As String = "<status>" + oStore.StoreItem_GetProperty("PR_ME_FLAGSTATUS").ToString + "</status>"

                        Dim WrapperEnd As String = "</message>"

                        XMLFile = XMLFile + WrapperStart + ItemId + MessageDate + Attachments + From + Subject + Size + Status + WrapperEnd
                    Loop While (oStore.StoreFolder_FindNextItem() = 1)
                    XMLFile = "<messages>" + XMLFile + "</messages>"
                End If
                APIResult = oStore.StoreFolder_FindClose()
                APIResult = oStore.StoreFolder_Close()
            Else
                Throw New ArgumentException("Invalid Mailbox!")
            End If
        End If
        XMLFile = "<result status=""Success"">" + XMLFile + "</result>"
    Catch ex As Exception
        XMLFile = "<result status=""Err""><reason>" + ex.Message + "</reason></result>"
    End Try
    Return XMLFile
End Function

Private Function fnGetTotalCount(Username As String, Postoffice As String) As String
    Dim XMLFile As String = ""
    Dim c As Integer = 0
    Try
        If Len(Username) <= 0 Or Len(Postoffice) <= 0 Then
            Throw New ArgumentException("Invalid Parameters!")
        Else
            Dim oMailbox As New MailEnable.Administration.Mailbox
            oMailbox.Postoffice = Postoffice
            oMailbox.MailboxName = Username
            oMailbox.Status = 1

            If oMailbox.GetMailbox() = 1 Then
                Dim APIResult As Long
                Dim oStore As New MailEnable.Store
                APIResult = oStore.StoreFolder_Open(Postoffice, Username, "\Inbox", 0, 1)
                If oStore.StoreFolder_FindFirstItem() = 1 Then
                    Do
                        c = c + 1
                    Loop While (oStore.StoreFolder_FindNextItem() = 1)
                    XMLFile = "<count>" + c.ToString + "</count>"
                End If
                APIResult = oStore.StoreFolder_FindClose()
                APIResult = oStore.StoreFolder_Close()
            Else
                Throw New ArgumentException("Invalid Mailbox!")
            End If
        End If
        XMLFile = "<result status=""Success"">" + XMLFile + "</result>"
    Catch ex As Exception
        XMLFile = "<result status=""Err""><reason>" + ex.Message + "</reason></result>"
    End Try
    Return XMLFile
End Function

Private Function fnGetUnreadCount(Username As String, Postoffice As String) As String
    Dim XMLFile As String = ""
    Dim c As Integer = 0
    Try
        If Len(Username) <= 0 Or Len(Postoffice) <= 0 Then
            Throw New ArgumentException("Invalid Parameters!")
        Else
            Dim oMailbox As New MailEnable.Administration.Mailbox
            oMailbox.Postoffice = Postoffice
            oMailbox.MailboxName = Username
            oMailbox.Status = 1

            If oMailbox.GetMailbox() = 1 Then
                Dim APIResult As Long
                Dim oStore As New MailEnable.Store
                APIResult = oStore.StoreFolder_Open(Postoffice, Username, "\Inbox", 0, 1)
                If oStore.StoreFolder_FindFirstItem() = 1 Then
                    Do
                        If oStore.StoreItem_GetProperty("PR_ME_READ").ToString = "0" Or oStore.StoreItem_GetProperty("PR_ME_READ").ToString = "" Then
                            c = c + 1
                        End If
                    Loop While (oStore.StoreFolder_FindNextItem() = 1)
                    XMLFile = "<count>" + c.ToString + "</count>"
                End If
                APIResult = oStore.StoreFolder_FindClose()
                APIResult = oStore.StoreFolder_Close()
            Else
                Throw New ArgumentException("Invalid Mailbox!")
            End If
        End If
        XMLFile = "<result status=""Success"">" + XMLFile + "</result>"
    Catch ex As Exception
        XMLFile = "<result status=""Err""><reason>" + ex.Message + "</reason></result>"
    End Try
    Return XMLFile
End Function

Private Function fnCreateMailAccount(Username As String, Postoffice As String) As String
    Dim XMLFile As String = ""
    Dim MailBoxQuota As Long = 102400
    Try
        If Len(Username) > 0 And Len(Postoffice) > 0 Then

            Dim oPostoffice As New MailEnable.Administration.Postoffice
            Dim oDomain As New MailEnable.Administration.Domain

            oPostoffice.Account = Postoffice
            oPostoffice.Name = Postoffice
            oPostoffice.Host = Postoffice
            oPostoffice.Status = 1
            If oPostoffice.GetPostoffice <> 1 Then
                CreatePostoffice(Postoffice, New Guid().ToString.Substring(20))
            End If

            Dim oLogin As New MailEnable.Administration.Login
            oLogin.Account = Postoffice
            oLogin.LastAttempt = -1
            oLogin.LastSuccessfulLogin = -1
            oLogin.LoginAttempts = -1
            oLogin.Password = ""
            oLogin.Rights = ""
            oLogin.Status = -1
            oLogin.UserName = Username & "@" & Postoffice
            If oLogin.GetLogin <> 1 Then
                oLogin.LastAttempt = 0
                oLogin.LastSuccessfulLogin = 0
                oLogin.LoginAttempts = 0
                oLogin.Password = Right(Guid.NewGuid().ToString, 16)
                oLogin.Rights = "USER"
                oLogin.Status = 1

                'Create Login
                If oLogin.AddLogin = 1 Then

                End If

                oLogin = Nothing

                Dim oMailbox As New MailEnable.Administration.Mailbox
                oMailbox.Postoffice = Postoffice
                oMailbox.MailboxName = Username
                oMailbox.RedirectAddress = ""
                oMailbox.RedirectStatus = 0
                oMailbox.Size = 0
                oMailbox.Limit = MailBoxQuota
                oMailbox.Status = 1

                'Create Mailbox
                If oMailbox.AddMailbox = 1 Then
                    '
                    ' Mailbox was added - What could go wrong!
                    '
                End If

                oMailbox = Nothing
                ' Finally, we need to assign address map(s) for the mailbox

                Dim oAddressMap As New MailEnable.Administration.AddressMap
                oAddressMap.Account = Postoffice
                oAddressMap.DestinationAddress = "[SF:" & Postoffice & "/" & Username & "]"
                oAddressMap.SourceAddress = "[SMTP:" & Username & "@" & Postoffice & "]"
                oAddressMap.Scope = 0
                If oAddressMap.AddAddressMap = 1 Then
                    '
                    ' Address Map was added too - What could go wrong!
                    '
                End If
                oAddressMap = Nothing
                XMLFile = "<result status=""Success""></result>"
            Else
                Throw New ArgumentException("Account already exists!")
            End If
        Else
            Throw New ArgumentException("Invalid Parameters!")
        End If
    Catch ex As Exception
        XMLFile = "<result status=""Err""><reason>" + ex.Message + "</reason></result>"
    End Try
    Return XMLFile
End Function

Function CreatePostoffice(sPostoffice As String, sPassword As String) As String
    Dim oPostOffice As New MailEnable.Administration.Postoffice
    Dim oMailbox As New MailEnable.Administration.Mailbox
    Dim oLogin As New MailEnable.Administration.Login
    Dim lResult As Long
    CreatePostoffice = False
    If Len(sPostoffice) > 0 And Len(sPassword) > 0 Then
        oPostOffice.Account = sPostoffice
        oPostOffice.Name = sPostoffice
        oPostOffice.Status = 1
        lResult = oPostOffice.AddPostoffice
        If (lResult = 1) Then
            oMailbox.Postoffice = sPostoffice
            oMailbox.Limit = -1
            oMailbox.MailboxName = "Postmaster"
            oMailbox.RedirectAddress = ""
            oMailbox.RedirectStatus = 0
            oMailbox.Status = 1
            lResult = oMailbox.AddMailbox
            If (lResult = 1) Then
                oLogin.Account = sPostoffice
                oLogin.Description = "Postmaster Mailbox"
                oLogin.Password = sPassword
                oLogin.Rights = "ADMIN"
                oLogin.Status = 1
                oLogin.UserName = "Postmaster@" & sPostoffice
                lResult = oLogin.AddLogin
                If (lResult = 1) Then
                    CreatePostoffice = True
                End If
            End If
        End If
    End If
    oPostoffice = Nothing
    oMailbox = Nothing
    oLogin = Nothing
End Function


End Class

虽然这不是完整的答案,但您可以开始着手解决它。这边请。

将此MailEnable代码放在您的and邮件文件夹中,并从您的应用程序请求。

可以下载here的QueryStringModule

您的应用程序中使用QueryStringModule在MailEnable应用程序中对http请求进行加密和解密。

出于安全原因,仅允许在MailEnable web应用程序中使用您的应用程序IP。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20301993

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档