/ Forums / Advansys Formativ / Creating Solutions with Formativ / Trusted Application and Multiple Logins / Reply To: Trusted Application and Multiple Logins

#6944
stuartcross
Participant

    I am still having a few problems with getting the applet to use the trusted application to send the emails using the account I have connected to. The code I am using is below. I am able to search through the various mailboxes and find the relevant emails. When I then create a new mail message and attach these emails, it works on my account but not on the others. I believe it works for me because I am running the applet from within my GW account. I need to know how to send an email from an account I am connected to and then attach messages to these.

    const CMDLINE_PARAMS = “”
    ‘This is the domain we want to look for
    const DOMAIN = “hotmail.com”
    ‘This is who we want to forward the emails to
    const MANAGER = “manager@test.com”

    dim Msg
    dim StringList
    dim UserList
    dim MailFound
    dim iAccount
    dim ItemtypeCount
    dim iCount
    dim HRT

    ”””””””””””””””””””””””””””””””””””””””’
    ‘ Connects to the accounts specified in UserList and searches for emails
    ”””””””””””””””””””””””””””””””””””””””’
    Sub Main(Client, GWEvent)

    HRT = Chr(13) & Chr(10)
    Set UserList = Utilities.StringList
    UserList.Add(“account1”)
    UserList.Add(“crosss”)
    UserList.Add(“account2”)
    UserList.Add(“account3”)
    MailFound = 0
    ‘ Apply the trusted application credentials
    call GroupWise.Session.SetTrustedApplicationCredentials(“TrustedApp”, “1234”)
    itemtypeCount = 0
    Do While ItemtypeCount <> UserList.Count
    Set StringList = Utilities.StringList
    iSearch = UserList.Strings(ItemtypeCount)
    ‘ Use the Multilogin method to access the account
    on error resume next
    set iAccount = GroupWise.Session.Multilogin(iSearch, CMDLINE_PARAMS, null, egwPromptNever, null)
    ‘ Check if we were able to log into this users account
    if iAccount is nothing then
    MsgBox “Login Failed – Check the Trusted Application credentials and the command line paramters: ” & iSearch, 0, IDS_CAPTION
    else
    iFilter = (“(MAIL) AND (NOT OPENED)”)
    set iMessages = iAccount.AllMessages.find(iFilter)
    iCount = iMessages.Count
    if iCount > 0 then
    ‘ set each message object
    for x = 1 to iCount
    set Msg = iMessages.Item(x)
    Checkmail
    next
    end if
    ‘ Remember to clean up this message collection
    set iMessages = nothing
    end if
    ‘ Release the account object we obtained

    ItemTypeCount = ItemTypeCount + 1
    if MailFound > 0 then
    SendMail
    end if
    MailFound = 0
    set iAccount = nothing
    Loop
    ‘ SetTrustedApplicationCredentials with empty strings to remove the credentials
    ‘ from the current session. If we don’t do this, we will be able to multi-login
    ‘ to any account for the remainder of this GroupWise session. This may or may not
    ‘ be the desired effect…
    call GroupWise.Session.SetTrustedApplicationCredentials(“”,””)

    end Sub

    ”””””””””””””””””””””””””””””””””””””””’
    ‘ Check the Domain email is from and compare the time it was delivered with the current time
    ”””””””””””””””””””””””””””””””””””””””’
    function CheckMail
    dim sDate
    dim sTime
    dim sCurDate
    dim sCurTime

    if (Instr(1, LCase(Msg.Sender.EmailAddress), LCase(DOMAIN))) <> 0 then
    sDate=Utilities.DatetoISO(Msg.DeliveredDate)
    If (Instr(1, sDate, “T”,1) <> 0) then
    sArray = Split(sDate, “T”, -1, 1)
    sDate = sArray(0)
    sTime = sArray(1)
    End If
    sCurDate=Utilities.DatetoISO(Date+Time)
    If (Instr(1, sCurDate, “T”,1) <> 0) then
    sArray = Split(sCurDate, “T”, -1, 1)
    sCurDate = sArray(0)
    sCurTime = sArray(1)
    End If
    if sCurdate > sDate then
    StringList.Add(Msg.Sender.DisplayName&” !! “&Msg.Subject&” !! “&Msg.CreationDate&” !! “&Msg.MessageID)
    else
    if sCurDate = sDate then
    ‘if sCurTime-sTime > 20000 then
    if sCurTime-sTime > 1 then
    StringList.Add(Msg.Sender.DisplayName&” !! “&Msg.Subject&” !! “&Msg.CreationDate&” !! “&Msg.MessageID)
    End if
    End if
    End if
    CheckMail = TRUE
    MailFound = MailFound + 1
    exit function
    end if

    end function

    ‘——————————————————————————-
    ‘ Forward Emails to Manager
    ‘——————————————————————————-
    function SendMail

    dim MyArray

    Groupwise.NewMail
    Set NewMsg = GroupWise.ComposingItem
    NewMsg.To_ = MANAGER
    NewMsg.Subject = “Unopened Messages within 2 hour period”
    NewMsg.BodyText = HRT&HRT&HRT&”Forwarded Messages from : “&(iAccount.Owner)&HRT&HRT&”The attached messages have not been opened within the 2 hour period”
    for x = 0 to (StringList.Count -1)
    MyArray = Split(StringList.Strings(x), ” !! “, -1, 1)
    call GroupWise.ItemAttachmentAdd(“X00″,115,MyArray(3),”Test”)
    set NewMsg = nothing
    set Msg = nothing
    next
    GroupWise.ItemSend(0)
    end function