Seeking Advice on Best Approach for Email Handling with Attachments

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Seeking Advice on Best Approach for Email Handling with Attachments

18 Jul 2018, 19:34

TXShooter wrote:
FanaticGuru wrote:For something like this to work Headers[A_Index] would need to contain a column letter like "B" but the way you populated the array it will probably contain a header name like "Date".

Would my line of code above work?Columns[A_Index] := Chr(64+A_Index)
If you want to use the array approach, this might help.

Code: Select all

DropInColumnByHeader2("Amount", 123.45)

DropInColumnByHeader2(Header, Value)
{
	global xlApp
	static Headers
	if !xlApp ; create xlApp the first time
		xlApp := ComObjActive("Excel.Application")
	if !Headers ; get all the headers the first time
	{
		Headers := {}
		for Cell in xlApp.ActiveSheet.UsedRange.Rows(1).Cells
			Headers[Cell.Value] := Cell.Column
	}
	Header_Column := Headers[Header]
	Empty_Row := xlApp.Columns(Header_Column).Find("*",,,,,2).Row + 1
	xlApp.Cells(Empty_Row, Header_Column).Value := Value
}
This just creates an array where the key is the header name and the value is the column number the first time the function is called then after that it has the information it needs in the array. You just need an array that has all the headers and what column each is in. Using numbers and Cells is generally easier than using strings of letters and numbers with Range.

You might be able to make something like the Columns[A_Index] := Chr(64+A_Index) work. Basically it is just saying column 1 is equal to A and column 2 is equal to B, etc. Which does not seem very useful. You really need to use the header name and the column letter if you want to use with Range.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
TXShooter
Posts: 165
Joined: 13 Dec 2017, 09:27

Re: Seeking Advice on Best Approach for Email Handling with Attachments

14 Sep 2018, 18:56

I'm not finding anything that can be used to markup the text within the body of an email through a COM object via AHK. When I search for 'ahk com object body bold italics' on Google, the results appear to be focused more on dealing with OFT templates than creating the body using a com object. Is it possible to use a bold font for a specific word in AHK before passing it off to the com object?
FanaticGuru wrote:

Code: Select all

RecipientFirstName := "John"
Message =
(%

   Thank you %RecipientFirstName% for requesting today`'s sermon. We hope it brings you and your loved ones closer to the Will of God.

<strong>May the Lord Bless and Keep you this day.</strong>
)

MsgBox % Message
MsgBox % Markup(Message)

Markup(String)
{
	X:=1
	while (X := RegExMatch(String, "([^%]*?)%(\S*?)%([^%]*)", M, X+StrLen(M)))
		Result .= M1 %M2% M3
	return Result
}
FG
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Seeking Advice on Best Approach for Email Handling with Attachments

14 Sep 2018, 20:57

TXShooter wrote:I'm not finding anything that can be used to markup the text within the body of an email through a COM object via AHK. When I search for 'ahk com object body bold italics' on Google, the results appear to be focused more on dealing with OFT templates than creating the body using a com object. Is it possible to use a bold font for a specific word in AHK before passing it off to the com object?
FanaticGuru wrote:

Code: Select all

RecipientFirstName := "John"
Message =
(%

   Thank you %RecipientFirstName% for requesting today`'s sermon. We hope it brings you and your loved ones closer to the Will of God.

<strong>May the Lord Bless and Keep you this day.</strong>
)

MsgBox % Message
MsgBox % Markup(Message)

Markup(String)
{
	X:=1
	while (X := RegExMatch(String, "([^%]*?)%(\S*?)%([^%]*)", M, X+StrLen(M)))
		Result .= M1 %M2% M3
	return Result
}
FG
It is easy to do formatting in an HTML email.

Here is an example including the Markup function to expand variable names before putting into email.

Code: Select all

Recipient := "Them <[email protected]>"
Subject := "Reports"

RecipientFirstName := "John"
Message =
(%

   Thank you %RecipientFirstName% for requesting today`'s sermon. We hope it brings you and your loved ones closer to the Will of God.

<strong>May the <i>Lord</i> Bless and Keep you this day.</strong>
)
Body := Markup(Message)

;example of creating a MailItem and setting it's format to HTML
olMailItem := 0
MailItem := ComObjActive("Outlook.Application").CreateItem(olMailItem)
olFormatHTML := 2
MailItem.BodyFormat := olFormatHTML
MailItem.Subject := Subject
MailItem.HTMLBody := Body
Recipient := MailItem.Recipients.Add(Recipient)
Recipient.Type := 1 ; To: CC: = 2 BCC: = 3

MailItem.Display


Markup(String)
{
	X:=1
	while (X := RegExMatch(String, "([^%]*?)%(\S*?)%([^%]*)", M, X+StrLen(M)))
		Result .= M1 %M2% M3
	return Result
}
FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Exies, Google [Bot], hiahkforum, scriptor2016 and 116 guests