Topic
  • 12 replies
  • Latest Post - ‏2013-04-16T16:47:25Z by BuddyD
llandale
llandale
3035 Posts

Pinned topic fEmail_Outlook_CreateMail SentFrom

‏2011-02-08T15:42:57Z |

Help. Want to auto-send an email "from" this other account.

Below is my function to make and send an Outlook email. I want it to send the email from the DOORS admin account, not the current user (me). When I "Display" the email with this function (parameter in_AutoSend = false) and then manually send it, it works; the email is "from" the other address. But when I "Send" the email with this funtion (parameter in_AutoSend = true), it seems to ignore the "SentFrom" field and sends it always from "me".

I see my specified "SendFrom" field must be a valid address (which is isn't in this example).
 

string    gl_Ole_AppOutlook     = "Outlook.Application"       // Windows recognizes this as a running Outlook
 
bool    fOle_OK(string in_ResultFromOleCommand, in_NameOfOleCommand)
{
        if (!null in_ResultFromOleCommand)
        {  print "XX OLE Error:\t" in_NameOfOleCommand "\t[" in_ResultFromOleCommand "]\n"
         return(false)
        }
        else return(true)
}
 
 
//******************************
bool    fEmail_Outlook_CreateMail(bool in_AutoSend, string in_SendTo, in_SendCC,
                 in_SendBCC, in_SentFrom, in_Subject, in_Body)
{     // Create the Email message which requires that Outlook.exe is running.
        // in_SendTo, in_SendCC, in_SendBCC, and in_SentFrom should be valid 
        //      Email addresses separated by semi-colons;.
        // Send the Message when in_AutoSend, otherwise just display it.
        // When in_SentFrom is null then no such field is used
 
 
        bool    Result  = false
        OleAutoObj      oaoMessage      = null
        OleAutoObj      oaoOutlook      = oleGetAutoObject(gl_Ole_AppOutlook)
        if (null oaoOutlook)
        {  fOle_OK("Outlook not running", "GetOutlook")   // Log Error
           return(false)
        }
        OleAutoArgs     autoArgs        = create()
        clear(autoArgs)
        put(autoArgs, 0)           // 0 is Outlook's symbolic constant for mail item
 
        if(     fOle_OK(oleMethod(oaoOutlook, "CreateItem", autoArgs, oaoMessage), "CreateItem")    and
                fOle_OK(olePut(oaoMessage, "To",      in_SendTo),  "To")    and
                fOle_OK(olePut(oaoMessage, "CC",      in_SendCC),  "CC")    and
                fOle_OK(olePut(oaoMessage, "BCC",     in_SendBCC), "BCC")   and
                fOle_OK(olePut(oaoMessage, "Subject", in_Subject), "Subj")  and
                fOle_OK(olePut(oaoMessage, "Body",    in_Body),    "Body")  and
                (null in_SentFrom       or
                 fOle_OK(olePut(oaoMessage, "SentOnBehalfOfName", in_SentFrom),  "SentFrom")
                )
          )
        {             // Message created OK. Send or just Show it
           if (in_AutoSend)
                Result = fOle_OK(oleMethod(oaoMessage, "Send"), "Send")
           else Result = fOle_OK(oleMethod(oaoMessage, "Display"), "Display")
        }
        else Result = false
        delete(autoArgs)
        return(Result)
}    // end fEmail_Outlook_CreateMail()
 
 
string  ToField = "Louie.Landale@ngc.com"
string  SentFrom = "MyDoorsAdmin@ngcXX.com"
 
bool    SendIt = confirm("Confirm to Send; Cancel to Display")
fEmail_Outlook_CreateMail(SendIt, ToField, "", "", SentFrom , "Subject", "Body")

 

 

  • Louie

 

 

Updated on 2013-12-20T20:23:08Z at 2013-12-20T20:23:08Z by JAntley
  • Mathias Mamsch
    Mathias Mamsch
    2542 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2011-02-08T17:12:48Z  
    On my computer your code works fine. In both cases it is sent with the right "on behalf of" address. When I click "Confirm" I get an Outlook message "A script is trying to send an email, do you want to allow that?". And when I confirm this, the email is sent out correctly. Maybe something with your Outlook/MAPI configuration? I am using Outlook 2003, SP2. Regards, Mathias

    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
  • llandale
    llandale
    3035 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2011-02-09T14:26:17Z  
    On my computer your code works fine. In both cases it is sent with the right "on behalf of" address. When I click "Confirm" I get an Outlook message "A script is trying to send an email, do you want to allow that?". And when I confirm this, the email is sent out correctly. Maybe something with your Outlook/MAPI configuration? I am using Outlook 2003, SP2. Regards, Mathias

    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
    Guess I'm brain dead. Got a rule that copies my "sent" messages to my inbox. So I run the code and look at my Inbox, and I see a message from me to me. But that's my 'sent' message. If I wait 30 seconds I actually GET the message I sent, and THAT messages says I sent it on behalf of. Guess that's good enough.

    So in practice the calling function will add the From field also to the BCC field, so the DOORS admin account actually gets the message I sent and has some record of it.

    Thanks.

    • Louie
  • Stig0498
    Stig0498
    8 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2011-02-22T14:32:52Z  
    • llandale
    • ‏2011-02-09T14:26:17Z
    Guess I'm brain dead. Got a rule that copies my "sent" messages to my inbox. So I run the code and look at my Inbox, and I see a message from me to me. But that's my 'sent' message. If I wait 30 seconds I actually GET the message I sent, and THAT messages says I sent it on behalf of. Guess that's good enough.

    So in practice the calling function will add the From field also to the BCC field, so the DOORS admin account actually gets the message I sent and has some record of it.

    Thanks.

    • Louie
    Hi,
    I just tried the code above but get the following OLE error:

    CreateItem
  • Stig0498
    Stig0498
    8 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2011-02-22T14:35:48Z  
    • llandale
    • ‏2011-02-09T14:26:17Z
    Guess I'm brain dead. Got a rule that copies my "sent" messages to my inbox. So I run the code and look at my Inbox, and I see a message from me to me. But that's my 'sent' message. If I wait 30 seconds I actually GET the message I sent, and THAT messages says I sent it on behalf of. Guess that's good enough.

    So in practice the calling function will add the From field also to the BCC field, so the DOORS admin account actually gets the message I sent and has some record of it.

    Thanks.

    • Louie
    Hi,
    I just tried the code above but get the following OLE error:

    CreateItem OLE failure: Parameter not optional.

    any thoughts?

    Thanks
  • Mathias Mamsch
    Mathias Mamsch
    2542 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2011-02-22T15:51:43Z  
    • Stig0498
    • ‏2011-02-22T14:35:48Z
    Hi,
    I just tried the code above but get the following OLE error:

    CreateItem OLE failure: Parameter not optional.

    any thoughts?

    Thanks
    What version of Outlook are you using? Regards, Mathias

    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
  • Stig0498
    Stig0498
    8 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2011-02-23T15:10:53Z  
    What version of Outlook are you using? Regards, Mathias

    Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
    Hi
    I am using Outlook 2003

    just realised i have missed out the following lines of code

    clear(autoArgs)
    put(autoArgs, 0)

    This stops the error but DOORS just now hangs when I run it
  • Stig0498
    Stig0498
    8 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2011-02-23T15:27:25Z  
    • Stig0498
    • ‏2011-02-23T15:10:53Z
    Hi
    I am using Outlook 2003

    just realised i have missed out the following lines of code

    clear(autoArgs)
    put(autoArgs, 0)

    This stops the error but DOORS just now hangs when I run it
    Scratch that, working fine now. Thanks
  • SystemAdmin
    SystemAdmin
    3180 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2012-02-15T13:49:31Z  
    This is an amazing function.
    Is there a possibility to send an email to multiple groups?
    I'm used to do it with the sendEmailNotification function, using the Skip list
  • llandale
    llandale
    3035 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2012-02-15T16:43:24Z  
    This is an amazing function.
    Is there a possibility to send an email to multiple groups?
    I'm used to do it with the sendEmailNotification function, using the Skip list

    Maybe this works:

    string MakeDelimitedList(Skip in_skp, string in_Delim)
    {   // Turn the Skip into a delimited list
        // Skip's "Key" must be type "string"
       if (null in_skp)   return("")
       Buffer buf = create
       string Data, Key
       string Delim = ""
       for Data in in_skp do
       {  Key = (string key in_skp)
          buf += Delim
          buf += Key
          Delim = in_Delim    // get ready for next entry
       }
       string Results = stringOf(buf)
       delete(buf)
       return(Results)
    }  // end MakeDelimitedList()
    // I suppose you would do this:
    string ToField = MakeDelimitedList(skpMyEmailGroups, "; ")
    


    -Louie

    Updated on 2013-12-20T20:23:42Z at 2013-12-20T20:23:42Z by JAntley
  • SystemAdmin
    SystemAdmin
    3180 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2013-04-04T09:31:32Z  
    • llandale
    • ‏2012-02-15T16:43:24Z

    Maybe this works:

    <pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">string MakeDelimitedList(Skip in_skp, string in_Delim) { // Turn the Skip into a delimited list // Skip's "Key" must be type "string" if (null in_skp) return("") Buffer buf = create string Data, Key string Delim = "" for Data in in_skp do { Key = (string key in_skp) buf += Delim buf += Key Delim = in_Delim // get ready for next entry } string Results = stringOf(buf) delete(buf) return(Results) } // end MakeDelimitedList() // I suppose you would do this: string ToField = MakeDelimitedList(skpMyEmailGroups, "; ") </pre>


    -Louie

    Hi,

    Can you please let me know how to add the recipient email address in Cc Field in the script.

    Moreover it would be great if the particular mail has to be sent automatically in particular time.is that possible?

    Thanks,
    Shri
  • BuddyD
    BuddyD
    5 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2013-04-15T20:42:35Z  
    Hi,

    Can you please let me know how to add the recipient email address in Cc Field in the script.

    Moreover it would be great if the particular mail has to be sent automatically in particular time.is that possible?

    Thanks,
    Shri

    I'm going to try this also, I want to thank you a head of time.

    Johnny

  • BuddyD
    BuddyD
    5 Posts

    Re: fEmail_Outlook_CreateMail SentFrom

    ‏2013-04-16T16:47:25Z  
    • BuddyD
    • ‏2013-04-15T20:42:35Z

    I'm going to try this also, I want to thank you a head of time.

    Johnny

    Still in clean up of code mode, I'm using Outlook 2007.  I think I'm missing some code that is not included above.  sbhupa do you have your code working.  Is thier a missing piece.

    Attachments