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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
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

    • caramen
      By caramen
      I watched _OL_ItemSend&_OL_ItemFind&_OL_ItemCreate in OutlookEx UDF but hmmm
       
      Since it use the test environnement i cant get the orders of the mail creation
       
      Can someone make me win some time of reading all exemples script and lead me how to do one ?
      That whould be lovely.
      Gnight
    • water
      By water
      Extensive library to control and manipulate Microsoft Outlook.
      Theads: Development - General Help & Support - Example Scripts - Wiki
      BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort

      KNOWN BUGS (last changed: 2018-09-01)
      None
    • Gowrisankar
      By Gowrisankar
      Dear members, 
      I am working on a project where, emails from outlook are to be read and moved to various folders within the mailbox, based on the content of the emails.
      I used the below code for moving mails. It works fine when I run it against individual mail ids. But when I run it on Shared mailbox, the mails are not moved to respective folders.
      _OL_ItemMove($oOutlook, $sEntryId, Default, $sDestinationFolder) The value of $sEntryId is saved in an excel report initially. The current process reads the $sEntryId from the excel and passes it to "_OL_ItemMove" statement.
      Requesting the guidance of the forum members in this issue.
    • Gowrisankar
      By Gowrisankar
      Dear members of the forum,
      I need to open the attachments from mails without downloading them. Is it possible using OutlookEx UDF ?
    • Gowrisankar
      By Gowrisankar
      Dear members,
      I'm trying to get the attachments from mails using OutlookEx UDF and then save them in a particular location.
      The UDF considers even the signature images and other images in the mail body as attachments, and saves it in the folder I point. I want only the proper attachment documents to be saved.
      Requesting the guidance of the forum members.
       
       
      Thanks and regards,
      Gowrisankar R.
×