Suki

Add attachment

9 posts in this topic

#1 ·  Posted

Hi I am trying to add an attachment and send via outlook exchange. I am not going to use smtp, since the client is on exchange server. below is my code

 

Local $olMailItem = 0
    Local $olFormatRichText = 3
    Local $olImportanceLow = 0
    Local $olImportanceNormal = 1
    Local $olImportanceHigh = 2
    Local $olByValue = 1
    Local $olFormatHTML = 2
    Local $olFormatPlain = 1
    local $xyz=678
    $oOApp = ObjCreate("Outlook.Application")
    $oOMail = $oOApp.CreateItem ($olMailItem)
    $oOMail.Save
    With $oOMail
        ;.To = ("sukirti.x.sen@accenture.com")
        .Subject = "test mail"
        .BodyFormat = $olFormatRichText
        ;.Importance = $olImportanceNormal
        .Body = "test1234"& $xyz
        .attachments.add("C:\Users\sukirti.x.sen\Desktop\New folder (2)\PIndex.xls")
        .display
        ;.Send
    EndWith
    $oOApp=0

 

Mail is getting sent but attachment is not working , I am on outlook 2016. I tried many variants, .attachements.add , attachmentsadd etc but the attachment is not getting added to the mail. Everything else works though and I have run through hours of past discussions on this on the forums but the attachment is still not getting added

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Why don't you use my OutlookEX UDF?
Either use wrapper function _OL_Wrapper_SendMail or single function calls for _OL_ItemCreate, _OL_ItemAttachmentAdd and _OL_ItemSend.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted

your udf is great but it is too complex and I have time deadlines...any clues why the .attachments.add is not working?

I have seen posts in the forum where it is working for some people

Share this post


Link to post
Share on other sites

#4 ·  Posted

Complex?

#include <OutlookEX.au3>
Global $oOL = _OL_Open()
Global $oItem = _OL_Wrapper_SendMail($oOL[, "sukirti.x.sen@accenture.com", "", "", "Test Mail", "test1234", "C:\Users\sukirti.x.sen\Desktop\New folder (2)\PIndex.xls", $olFormatRichText, $olImportanceNormal)
If @error then Exit MsgBox(0, "Error", "@error = " & @error & ", @extended = " & @extended)
$oItem.Display()

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

unh the outlookex.au3 installation gives error when i try to build.

Anyway, i do not want to use something i do not understand. What is wrong with my code and why is attachments.add not working?

It looks simple, and the rest of the mail functionality is working

Share this post


Link to post
Share on other sites

#6 ·  Posted

hi- Please give up working on this, my code was right and of course your code was much better and much more correct than mine.

Issue - the excel files ends with .xlsx and not .xls , lesson learnt for me after spending 5 hours on this simple piece of code, many apologies for wasting your time

Share this post


Link to post
Share on other sites

#7 ·  Posted

Glad the problem could be solved :)
_OL_Wrapper_SendMail would have set @error to 5002. This tells us that the file to attach could not be found. That's not too complex, is it?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

hmm i did not get to look into that.. i am getting errors installing your outlook UDF. I have tried uninstall / install a couple of times but it gives errors, might be something to do with my system or OS. First couple of time i got an error - could not copy from outlookexconstants. I uninstalled deleted the edf and the zip extract and installed it again, but this time it gives me some variable being used without being declared error. I am 100% sure that this is something to do with the installation and I am going to delete all files and reinstall your UDF once i knock of whatever I am doing.there are many functions which you have written and which are definitely great to look through , both from a learning and usage perspective. Many thanks once agaim

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

What do you mean by installing? The UDF contains a lot of files (help file for each function, example for each function etc.) but you only need two files OutlookEX.au3 and OutlookEXConstants.au3,.
Save them in the directory where your script resides or the User Defined Include Directory. That's it.

This is documented in ReadMe.txt which is part of the downloaded file.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

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