2013-11-30 4 views
0

Я пытаюсь понять, как работает API MailEnable. До сих пор я мог только посмотреть документацию AJAX и получить команду LOGIN. Это как:Mailenable API AJAX Calls

AJAXRequest('LOGIN','Username='user'&Password='pass', false); 

Этой команда возвращает XML-строка, как

<BASEELEMENT SCHEMA="VALUE" METHOD="LOGIN"><RETURNVALUE>1</RETURNVALUE></BASEELEMENT> 

Это работает хорошо, ничего другого, чем команда LOGIN (Например LOG-OFF или LIST-СООБЩЕНИЯ) дает мне ошибку тайма-аут как

<BASEELEMENT SCHEMA="TIMEOUT" METHOD="LOGOUT"></BASEELEMENT> 

команды, которые я использую для LOG-OFF и LIST-СООБЩЕНИЙ это, и они оба дают мне ошибку ниже.

AJAXRequest('LIST-MESSAGES','Folder=/Inbox', false); 
AJAXRequest('LOG-OFF','ID=', false); 

Я использую примеры файлов от that. Я просто не могу понять, если я что-то упускаю, или эти примеры и документация не актуальны или имеют проблемы или что-то еще?

Спасибо!

(. Я не мог найти «MailEnable» тег помечать этот вопрос Жаль, что никто не имеет помеченный MailEnable раньше в StackOverflow, MailEnable форум похож на могилу: S)

+1

Вы нашли ответ на этот вопрос до настоящего времени? – Prasanth

+0

Нет, приятель. Я давно сдался ... – ilter

+1

Хотя я давно пробовал то же самое и не нашел никакого решения. Наконец, я разработал собственную систему http для отправки почты. Но, пройдя этот пост, подумал, что вы нашли решение для этого. Mail Enable документации выглядит устаревшей. Любые способы, если вы хотите получить дополнительную помощь, я могу разместить здесь свою собственную систему http. – Prasanth

ответ

1

Ok согласно комментариям Я: размещение самостоятельно написал почту Апи для MailEnable

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 = "[email protected]" & 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 

Хотя это не полный ответ, вы можете начать работать на нем. Сюда.
Поместите этот код ashx в папку электронной почты MailEnable и запрос от вашего приложения.
QueryStringModule доступен для скачивания here
QueryStringModule используется в вашем приложении для шифрования HTTP-запросов и расшифровки в приложении MailEnable.
Разрешить только IP-адрес приложения в веб-приложении MailEnable по соображениям безопасности.

+0

Я поддержал ваш ответ и комментарии в качестве благодарности за ваши просьбы. Я надеюсь попробовать, как только закончу проекты под рукой;) Спасибо! – ilter