Jump to content

Attach multiple files for email with variable names?


Recommended Posts

Hello,

Curious if I can send multiple attachments with variable naming? I have a few snips for sending email with attachments. I've tried a few methods I found here on the forum with no luck.

My code so far will open a Crystal Reports file, prompt for input for the report number, then it opens, prints and exports to a folder named "Reports" on the %userprofile%\desktop\

Im currently working on the next step of prompting to email the report (after the print out is verified) - a simple yes or no.

If yes, attach $input.pdf

If no , abort or exit.

Im working within terminal services, so the %userprofile% comes in handy.

Thank you for your time.

Below is my code minus the username and password.

=====BEGIN=====

Run('C:\WINDOWS\EXPLORER.EXE /n,/e,F:\SHARED\Wall Street Tickets\Cumberland Account.rpt')

WinWaitActive("Crystal Reports - [Cumberland Account]","")

$input = InputBox("Window title", "Enter your variable:")

Send("{F5}")

WinWaitActive("Refresh Report Data","")

Send("{TAB}{TAB}{DOWN}{ENTER}")

WinWaitActive("Enter Parameter Values","")

Send( $input, 1 )

Send("{ENTER}")

WinWaitActive("ODBC (RDO)","")

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}username{TAB}password{ENTER}")

WinWaitActive("Crystal Reports - [Cumberland Account]","")

WinActivate("Crystal Reports - [Cumberland Account]","")

Send("{ALTDOWN}fpp{ALTUP}")

WinActivate("Print","")

Send("{ENTER}")

WinWaitActive("Crystal Reports - [Cumberland Account]","")

WinWaitActive("Crystal Reports - [Cumberland Account]","")

Send("{ALTDOWN}fe{ALTUP}")

WinWaitActive("Export","")

Send("{ENTER}")

WinWaitActive("Export Options","")

Send("{ENTER}")

WinWaitActive("Choose export file","")

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{SPACE}")

WinWaitActive("Choose export file","")

Send("{SHIFTDOWN}5{SHIFTUP}userprofile{SHIFTDOWN}5{SHIFTUP}\desktop\reports{ENTER}")

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{DEL}")

Send( $input, 1)

Send("{ENTER}")

=====END=====

Hello,

Curious if I can send a file or multiple attachments with variable naming? I have a few snips for sending email with attachments. I've tried a few methods I found here on the forum with no luck.

My code so far will open a Crystal Reports file, prompt for input for the report number, then it opens, prints and exports to a folder named "Reports" on the %userprofile%\desktop\

Im currently working on the next step of prompting to email the report (after the print out is verified) - a simple yes or no.

If yes, attach $input.pdf

If no , abort or exit.

Im working within terminal services, so the %userprofile% comes in handy.

Thank you for your time.

Below is my code minus the username and password.

=====BEGIN=====

Run('C:\WINDOWS\EXPLORER.EXE /n,/e,F:\SHARED\Wall Street Tickets\Cumberland Account.rpt')

WinWaitActive("Crystal Reports - [Cumberland Account]","")

$input = InputBox("Window title", "Enter your variable:")

Send("{F5}")

WinWaitActive("Refresh Report Data","")

Send("{TAB}{TAB}{DOWN}{ENTER}")

WinWaitActive("Enter Parameter Values","")

Send( $input, 1 )

Send("{ENTER}")

WinWaitActive("ODBC (RDO)","")

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}username{TAB}password{ENTER}")

WinWaitActive("Crystal Reports - [Cumberland Account]","")

WinActivate("Crystal Reports - [Cumberland Account]","")

Send("{ALTDOWN}fpp{ALTUP}")

WinActivate("Print","")

Send("{ENTER}")

WinWaitActive("Crystal Reports - [Cumberland Account]","")

WinWaitActive("Crystal Reports - [Cumberland Account]","")

Send("{ALTDOWN}fe{ALTUP}")

WinWaitActive("Export","")

Send("{ENTER}")

WinWaitActive("Export Options","")

Send("{ENTER}")

WinWaitActive("Choose export file","")

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{SPACE}")

WinWaitActive("Choose export file","")

Send("{SHIFTDOWN}5{SHIFTUP}userprofile{SHIFTDOWN}5{SHIFTUP}\desktop\reports{ENTER}")

Send("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{DEL}")

Send( $input, 1)

Send("{ENTER}")

=====END=====

Edited by ironsled
Link to comment
Share on other sites

You did already post this question on 24 July 2012 - 04:19 AM? So this means you posted in another thread? Why did you open a second thread asking the same qeustion?

That's nothing the forum rules permit.

BTW: Which mail program do you want to use?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@Water, Yes I asked a question on July 20th about something completely different. Which I figured out on my own.

Now Im asking about "Variables" and if it is possible to use them to attach files?

Curious if there is a way to use the SMTP script I see floating around on the forum within the code:

$AttachFiles = @DesktopDir & ""

Sorry if I went against the forum rules. It was not intended.

Cheers!

Link to comment
Share on other sites

The original allows to pass multiple attachments:

"$AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed"

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Thank you for the reply and the link.

Is it possible to use the input variable to attach the files? The same code I used to begin the script to pull up the report number and export it with the same name. Now I want to attach that same file.

Example: $input = InputBox("Window title", "Enter your variable:")

"$AttachFiles = "@DesktopDir & "Reports$input.pdf" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed"

Thank you!

Link to comment
Share on other sites

Sure:

$AttachFiles = @DesktopDir & "Reports" & $input & ".pdf"
But I wouldn't use InputBox to let the user enter the name of a file but use function FileOpenDialog so the user can select one or multiple files.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

:D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@Waters, Hi again! Quick question for you. Is it possible to include a signature within the email script listed below?

I downloaded the OutlookEX UDF script, which I pick the signature and then copies to clipboard. This works well, but Im not sure how to go about imputing this data within this email script.

Again, many thanks for your help!

;##################################

; Include

;##################################

#Include<file.au3>

;##################################

; Variables

;##################################

$SmtpServer = "" ; address for the smtp-server to use - REQUIRED

$FromName = "" ; name from who the email was sent

$FromAddress = "" ; address from where the mail should come

$ToAddress = "" ; destination address of the email - REQUIRED

$Subject = "" ; subject from the email - can be anything you want it to be

$Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail

$AttachFiles = @DesktopDir & "Reports" & $input & ".pdf" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed

$CcAddress = "" ; address for cc - leave blank if not needed

$BccAddress = "" ; address for bcc - leave blank if not needed

$Importance = "High" ; Send message priority: "High", "Normal", "Low"

$Username = "" ; username for the account used from where the mail gets sent - REQUIRED

$Password = "" ; password for the account used from where the mail gets sent - REQUIRED

$IPPort = 25 ; port used for sending the mail

$ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS

;~ $IPPort=465 ; GMAIL port used for sending the mail

;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS

;##################################

; Script

;##################################

Global $oMyRet[2]

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")

$rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)

If @error Then

MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)

EndIf

;

; The UDF

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)

Local $objEmail = ObjCreate("CDO.Message")

$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'

$objEmail.To = $s_ToAddress

Local $i_Error = 0

Local $i_Error_desciption = ""

If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress

If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress

$objEmail.Subject = $s_Subject

If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then

$objEmail.HTMLBody = $as_Body

Else

$objEmail.Textbody = $as_Body & @CRLF

EndIf

If $s_AttachFiles <> "" Then

Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")

For $x = 1 To $S_Files2Attach[0]

$S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])

;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console

If FileExists($S_Files2Attach[$x]) Then

ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)

$objEmail.AddAttachment($S_Files2Attach[$x])

Else

ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)

SetError(1)

Return 0

EndIf

Next

EndIf

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer

If Number($IPPort) = 0 then $IPPort = 25

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort

;Authenticated SMTP

If $s_Username <> "" Then

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password

EndIf

If $ssl Then

$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

EndIf

;Update settings

$objEmail.Configuration.Fields.Update

; Set Email Importance

Switch $s_Importance

Case "High"

$objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"

Case "Normal"

$objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"

Case "Low"

$objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"

EndSwitch

$objEmail.Fields.Update

; Sent the Message

$objEmail.Send

If @error Then

SetError(2)

Return $oMyRet[1]

EndIf

$objEmail=""

EndFunc ;==>_INetSmtpMailCom

;

;

; Com Error Handler

Func MyErrFunc()

$HexNumber = Hex($oMyError.number, 8)

$oMyRet[0] = $HexNumber

$oMyRet[1] = StringStripWS($oMyError.description, 3)

ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)

SetError(1); something to check for when this function returns

Return

EndFunc ;==>MyErrFunc

Link to comment
Share on other sites

Use function ClipGet and add the result to $Body.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hello! Finally making some serious headway with my AutoIT project. Currently have the script prompt for 2 inputs. Im curious if I can auto name the export of the file with the 2 inputs fields.

Right now I have it naming the export using:

Send ( $input2 & ".pdf")

Is there a way to Send $input & $input2 ".pdf" to name the file? Input = Ticket number and Input2 = CUSIP number.

This would be ideal if the output of both as the name of the pdf file.

Below is my script with the email portion removed.

Many thanks again for your help!!

DirCreate ( @DesktopDir & "Reports" )

DirCreate ( @DesktopDir & "Reports Processed" )

;Sleep (500)

Run('C:WINDOWSEXPLORER.EXE /n,/e,F:SHAREDWall Street TicketsCumberland Account.rpt')

WinWaitActive("Crystal Reports - [Cumberland Account]","")

$input = InputBox("CA 1Click v1.0", "Enter the Ticket Number:")

;MsgBox(0,"User input is..",$input)

Send("{F5}")

ControlClick("Refresh Report Data", "", "[CLASS:Button; INSTANCE:5]")

ControlClick("Refresh Report Data", "", "[CLASS:Button; INSTANCE:1]")

WinWaitActive("Enter Parameter Values","")

Send( $input, 1 )

Send("{ENTER}")

WinWaitActive("ODBC (RDO)","")

ControlClick("ODBC (RDO)", "", "[CLASS:Edit; INSTANCE:2]")

Send( "{bs 10}username")

ControlClick("ODBC (RDO)", "", "[CLASS:Edit; INSTANCE:3]")

Send( "passwd")

ControlClick("ODBC (RDO)", "", "[CLASS:Button; INSTANCE:4]")

WinWaitActive("Crystal Reports - [Cumberland Account]","")

WinActivate("Crystal Reports - [Cumberland Account]","")

$input2 = InputBox("CA 1Click v1.0", "Enter the CUSIP#")

Sleep (1000)

Local $answer = MsgBox(262148, "You must click YES to proceed", "Do you want to print report #" & $input & " ?" )

; Check the user's answer to the prompt (see the help file for MsgBox return values)

; If "No" was clicked (7) then exit the script

If $answer = 7 Then

MsgBox(0, "CA 1CLICK REPORTS v1.0", "OK, Bye!")

Exit

EndIf

Send("{ALTDOWN}fpp{ALTUP}")

WinActivate("Print","")

Send("{ENTER}")

WinWaitActive("Crystal Reports - [Cumberland Account]","Cumberland Account")

Send("{ALTDOWN}fe{ALTUP}")

WinWaitActive( "Export","")

ControlClick("Export", "", "[CLASS:Button; INSTANCE:1]")

WinWaitActive("Export Options","")

ControlClick("Export Options", "", "[CLASS:Button; INSTANCE:4]")

ControlClick("Export Options", "", "[CLASS:Button; INSTANCE:1]")

WinWaitActive("Choose export file","")

Send( "{DEL}")

Send( "%userprofile%desktopreports" & $input2 & ".pdf")

Send("!S")

Sleep (500)

WinWaitActive("Crystal Reports - [Cumberland Account]","Cumberland Account")

Send( "{ALT}fx")

Send( "{TAB 1}")

Send( "{ENTER}")

;Sleep (500)

;$input3 = InputBox("CA 1CLICK v1.0 PDF Encryption", "Password protect report #" & $input & "? Please type password:")

Run('C:Program Files (x86)Acro SoftwareCutePDF ProCutePDF.exe')

WinWaitActive( "CutePDF Professional")

Send("{ALT}fo")

WinWaitActive("Select File:")

Send("{TAB 4} {SPACE}")

Send("%userprofile%desktopreports{ENTER}")

WinWaitActive("Select File:")

ControlClick("Select File:", "", "[CLASS:ComboBox; INSTANCE:1]")

Send( $input2 & ".pdf")

Send( "{ENTER}")

Send( "{ALT}ts")

Sleep (500)

ControlClick("Standard Security", "", "[CLASS:Edit; INSTANCE:1]")

Send( $input2 & ".pdf")

Sleep (500)

ControlClick("Standard Security", "", "[CLASS:Button; INSTANCE:3]")

ControlClick("Standard Security", "", "[CLASS:Edit; INSTANCE:2]")

Send( "passwd")

;Send( $input3, 1 )

Sleep (500)

ControlClick("Standard Security", "", "[CLASS:Button; INSTANCE:11]")

ControlClick("Password", "", "[CLASS:Edit; INSTANCE:1]")

Send( "passwd")

;Send( $input3, 1 )

Sleep (500)

ControlClick("Password", "", "[CLASS:Button; INSTANCE:1]")

Send("{ALT}FX")

Sleep (500)

FileMove (@DesktopDir & "Reports*.*", @DesktopDir & "Reports Processed", 9)

DirRemove (@DesktopDir & "Reports")

Sleep (500)

$oShell = ObjCreate("SAPI.SpVoice") ; Get the Windows SAPI Object

$oShell.Speak("Good Bye")

Sleep (500)

ProcessClose("SciTE.exe")

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...