Outlook attachment Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Outlook attachment

18 Feb 2019, 03:29

I'm trying to open a new email via Outlook and attach a file the user has selected beforehand. I'm pretty sure it used to work at some point during development but it seems like it broke.

Code: Select all

#SingleInstance, force
FileSelectFile, currentfile,,%A_Desktop%, Datei auswählen..., *.ps5
		if (currentfile = "")
			{
				SoundPlay, *16
				MsgBox, 16, Fehler!,Sie haben keine Datei ausgewählt.
				return
			}
		Loop, %currentfile%
			currentpath := A_LoopFileDir
	InputBox, ausbuchen_name, PS4000 Ablage, Für wen wird die Sicherung ausgebucht?,,,150
		if ausbuchen_name =
			MsgBox,, Fehler!, Sie haben keinen Namen angegeben, bitte erneut versuchen.
		else
			{
				FileDelete, %currentPath%\*übergeben*.ps5
				FormatTime, CurrentDateTime,, yyyy-MM-dd_HH-mm
				FileAppend, , %currentPath%\%CurrentDateTime% ACHTUNG! Projekt übergeben an %ausbuchen_name%.ps5
					if ErrorLevel
						MsgBox,, Fehler!, Achtung, es wurde keine Datei erzeugt!
					else
						{
							SplashTextOn,,25, Status, Datei wurde erzeugt.
							Sleep, 750
							SplashTextOff
							Run, OUTLOOK.EXE /c ipm.note /a %currentfile%
							Gui, Destroy
						}
				currentfile :=""
				currentPath :=""
				ausbuchen_name :=""
			}
	return
	
For some reason this works though:

Code: Select all

#SingleInstance, force

currentfile = C:\Users\%A_UserName%\Desktop\test.txt
Run, OUTLOOK.EXE /c ipm.note /a %currentfile%
Can anyone tell me what I'm not seeing here?
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Outlook attachment

18 Feb 2019, 14:33

I'm a little lost because of the language, but shouldn't currentfile be updated to be the same as the path you use on FileAppend? I could be wrong but it doesn't hurt checking it out.
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Re: Outlook attachment

19 Feb 2019, 01:53

%currentfile% returns the complete path of the file, as it should. It works fine when used as a single-line script (see initial post), just not in the complete script.
User avatar
Frosti
Posts: 426
Joined: 27 Oct 2017, 14:30
Contact:

Re: Outlook attachment

19 Feb 2019, 07:21

Why not using COM? And proof your whole script, maybe you use the variable "currentfile" twice and empty it in another thread?
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Re: Outlook attachment

19 Feb 2019, 08:16

COM??
Script seems good, I checked the variable via a MsgBox and it checks out.

I maybe should have mentioned it's Outlook that's throwing an error and not AHK itself. Whoops.

The command line argument is not valid. Verify the switch you are using
safetycar
Posts: 435
Joined: 12 Aug 2017, 04:27

Re: Outlook attachment  Topic is solved

19 Feb 2019, 10:04

Can you test with the same filename that fails in the complete script?

There are sometimes characters that give problems, usually spaces. The fix for spaces is usually wrapping the filepath in quotes simply like Run, OUTLOOK.EXE /c ipm.note /a "%currentfile%".
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Re: Outlook attachment

20 Feb 2019, 02:02

You, dear Sir, are my hero!
User avatar
tonkomnom
Posts: 37
Joined: 25 Jul 2018, 02:53
Contact:

Re: Outlook attachment

20 Feb 2019, 02:53

I'm pretty sure it used to work at some point during development but it seems like it broke.
Just checked one of the earlier builds and, tadaa, that's how I did it before I changed it for whatever reason. :roll:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mebelantikjaya and 289 guests