Jump to content
Ligy

OutlookEx Sending email from different email address

Recommended Posts

Ligy

Hello everyone.

Could you, please, help me with following problem?

I need to send an email as different sender. The way "on behalf" does not fit me well enough. Much better for me would be something like declaring account credentials of the email i want to use and then use something like SendUsingAccount, but I am not able to figure out, how to get it from current OutlookEx.au3. Do you have any idea? Thanks a lot.

 

Best Regards,

Ligy

Share this post


Link to post
Share on other sites
water

I just played with the example posted in the wiki using property "SentOnBehalf" and it works pretty well.
I use Outlook 2010 on Windows 7.

Which version of Outlook do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ligy

Also 2010. I am not able to get it work. Don't know, if it's because some security policies, but when I do it from outlook (new email -> choose different account as from ) it works, when I try to do it via script - "you don't have permission".

Second thing - if you do that SentOnBehalf, how it appears to the recipient? Because to me it is appearing like "From: name1 on behalf of name2" and that's not acceptable for me, i really need to have there only the name2

Share this post


Link to post
Share on other sites
water

Could you please run example script _OL_AccountGet.au3?
If you find the account you want to send from in the displayed array then I've got a working script for you ;)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ligy

Row|Col 0|Col 1|Col 2|Col 3|Col 4|Col 5|Col 6|Col 7|Col 8
[0]|1|9|||||||
[1]|0|*******|************|*****||*||*****|**.**.**.****


* = my main account

 

So, i suppose the others are missing :/

 

Share this post


Link to post
Share on other sites
water

Strange. Only one account in your profile.

How do you select "name2" when sending a mail "by hand"?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ligy

Well. It's company email, so maybe there are some security rules, so I am not able to get it externally. But when I start a new email and I click "from" button and choose one of the accounts i have been granted full access (sending emails etc.), I am able to send email as that account.

Share this post


Link to post
Share on other sites
water

If you select "File > Info" in Outlook how many accounts do you see?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ligy

Only mine

Share this post


Link to post
Share on other sites
water

So there seems to be another way you access this account (not by your profile). Can you ask your sysadmins how they assign the second user?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ligy

Ok, so I were able to get more accounts from that AccountGet func. I added whole account to my profile. So now i get more of them. I also found a script for sending from another account:

#include "OutlookEX.au3"

Global $oOL = _OL_Open()
; Get the list of accounts from your Outlook profile
Global $aAccounts = _OL_AccountGet($oOL)
; Create the mail item
Global $oItem = _OL_ItemCreate($oOL, $olMailItem, "", "", _
  "Subject=TestMail", "BodyFormat=" & $olFormatHTML, "HTMLBody=Bodytext in <b>bold</b>.")
; Set the second account object from your profile to send the mails from
$oItem.SendUsingAccount = $aAccounts[2][4]
; Add a recipient and resolve it
_OL_ItemRecipientAdd($oOL, $oItem, Default, $olTo, "Jon Doe")
; Send the mail
_OL_ItemSend($oOL, $oItem)
; Close Outlook connection
_OL_Close($oOL)

 

Unfortunately i always get this error message: "Variable must be of type "Object".: for the red part.  I tried every possible combination of indexes. Any Idea?
 

Edited by Ligy

Share this post


Link to post
Share on other sites
water

Insert some error checking to your script. Something like this:

#include "OutlookEX.au3"

Global $oOL = _OL_Open()
ConsoleWrite("Open: " & @error & "-" & @extended & @CRLF)
; Get the list of accounts from your Outlook profile
Global $aAccounts = _OL_AccountGet($oOL)
ConsoleWrite("GetAccounts: " & @error & "-" & @extended & @CRLF)
; Create the mail item
Global $oItem = _OL_ItemCreate($oOL, $olMailItem, "", "", _
  "Subject=TestMail", "BodyFormat=" & $olFormatHTML, "HTMLBody=Bodytext in <b>bold</b>.")
ConsoleWrite("ItemCreate: " & @error & "-" & @extended & @CRLF)
; Set the second account object from your profile to send the mails from
$oItem.SendUsingAccount = $aAccounts[2][4]
ConsoleWrite("SendUsingAccount: " & @error & "-" & @extended & @CRLF)
; Add a recipient and resolve it
_OL_ItemRecipientAdd($oOL, $oItem, Default, $olTo, "Jon Doe")
ConsoleWrite("RecipientAdd: " & @error & "-" & @extended & @CRLF)
; Send the mail
_OL_ItemSend($oOL, $oItem)
ConsoleWrite("Send: " & @error & "-" & @extended & @CRLF)
; Close Outlook connection
_OL_Close($oOL)

What do you get?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ligy

Open: 0-1
GetAccounts: 0-0
ItemCreate: 1000-0

"C:\path to the file" (125) : ==> Variable must be of type "Object".:
$oItem.SendUsingAccount = $aAccounts[2][4]
$oItem^ ERROR

Share this post


Link to post
Share on other sites
water

Can you please post the exact _OL_ItemCreate statement (mask sensitive information).
@error = 1000 means: Property does not exist.

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ligy

Global $oOutlook =  _OL_Open()
ConsoleWrite("Open: " & @error & "-" & @extended & @CRLF)

Global $aAccounts = _OL_AccountGet($oOutlook)
ConsoleWrite("GetAccounts: " & @error & "-" & @extended & @CRLF)

Global $oItem = _OL_ItemCreate($oOutlook, $olMailItem, "", "", $eSubject, "BodyFormat=" & $olFormatHTML, $eBody)
ConsoleWrite("ItemCreate: " & @error & "-" & @extended & @CRLF)

Share this post


Link to post
Share on other sites
water

I assume $eSubject and $eBody just contain the Subject and the Body. You need to specify the property to be set with this values. So it schould be:

Global $oItem = _OL_ItemCreate($oOutlook, $olMailItem, "", "", "Subject=" & $eSubject, "BodyFormat=" & $olFormatHTML, "HTMLBody=" & $eBody)

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Ligy

Yep, that was it, how stupid of me. Thank you very much, it's working now. Thanks for all help, I learnt more again. ;-)

Share this post


Link to post
Share on other sites
water

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
iCal (2019-01-22 - Version 0.1.0.0) - Download - General Help & Support
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • water
      By water
      I just noticed that Outlook does not allow to import iCal events programmatically.
      I might implement some of the iCalendar data format (RFC 55459) if someone is interested
      Please post here or click the "Like" button if you think this is a good idea
      Edit: For download please see my signature
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Friends,
      I am having a requirement where i have to automate outllook.I have to send mail using outlook.Whe i went through the forum i got OutLookEx.au3 but when i am trying to use this i am getting error can anyone help me in using this? @water
    • Gowrisankar
      By Gowrisankar
      Dear members of the forum,
      I'm working on a project where incoming emails are to be analyzed based on the subject line and moved to various folders in a shared mailbox.
      I'm using "OutlookEx.au3" of @water. The macro can can move emails  to any folder that I newly create. But the macro couldn't move emails to specific folders that are already existing.
      I checked the permission levels of those folders and found that nothing is wrong with that. The function I use is _OL_ItemMove.
      Please guide me how to proceed further. Thanks in advance.
      -Gowrisankar.
       
    • nooneclose
      By nooneclose
      Good morning everyone, I thought I had already solved this issue but it turns out I did not. 
      My code finds unread emails with this specific subject line of "request" but when I change the subject to SKIPPED + "request" = ("SKIPPED request") the program still finds the email and tries to process it. I only want to process emails with the exact match subject of "request".
      Here is my code that "finds" the unread emails with the subject of "request" or so I thought. 
      Func ListUnreadEmails() ;******************************************************************************* ; Lists all unread E-mails from the folder Outlook-UDF-Test ;******************************************************************************* ; Stores all the unRead emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "request", "EntryID,Subject", "", 1) ; Displays the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Gets the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) EndFunc It acts as if any part of the subject containing the word "request" and the email is unread that it will try to process it. (I think)
    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
×