COM programming issues

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
EagleKen
Posts: 3
Joined: 18 Oct 2013, 10:48

COM programming issues

Post by EagleKen » 18 Oct 2013, 10:57

Trying to send emails through Lotus Notes (to make it more tolerable to work with) by using some COM programming.

The code that I have works quite well, when I want to use a single email address. However if I want to use more, it seems to require an array. No matter what I do I simply cannot get it to recognize more than one address...

If anyone has any insight, and can at least point me in the right direction, I would really appreciate it.

Thanks

Code: Select all


			to := ["email1@server.com","email2@server.ca"]
;			to.Insert("email2@server.ca")
;			to.Insert("email2@server.ca")
;			to := "email1@server.com, email2@server.ca"
			cc := ""
			bcc := ""
			
		notes := ComObjCreate("Lotus.NotesSession")
		notes.initialize()
;		notes.Initialize("<password>") 
		Maildb := notes.GETDATABASE("", "D:\Data\Notes\xxxxxxx.nsf")
		MailDoc := Maildb.CREATEDOCUMENT
		MailDoc.ReplaceItemValue("Form", "Memo")
		MailDoc.ReplaceItemValue("SendTo", to)
		

		if (cc)
			MailDoc.ReplaceItemValue("CopyTo", cc)
		if (bcc)
			MailDoc.ReplaceItemValue("BlindCopyTo", bcc)
		
		MailDoc.ReplaceItemValue("Subject", subject)	
		Body := MailDoc.CREATERICHTEXTITEM("Body")
		Body.APPENDTEXT(body)
		
		
		
		if (attach) {
			MsgBox, attach has text in it
		} else {
			MsgBox, attach has nothing in it
		}
		
;			IfExist, %attach% {
;				Body.addNewLine(2)
;				Body.EMBEDOBJECT(1454, "", attach, "Attachment")
;			} 
;			IfNotExist, %attach% {
;				msgbox, File doesn't exist
;			}		
		
		
		
		MailDoc.SAVEMESSAGEONSEND := True
		FormatTime, CurrentDateTime, , MM/dd/yyyy HH:mm:ss
;		MsgBox The current time and date (date first) is %CurrentDateTime%.
		MailDoc.ReplaceItemValue("PostedDate", CurrentDateTime)
;		MailDoc.PostedDate(CurrentDateTime)
		MailDoc.SEND(False)
Edit: hid personal stuff

User avatar
MilesAhead
Posts: 232
Joined: 03 Oct 2013, 09:44

Re: COM programming issues

Post by MilesAhead » 18 Oct 2013, 14:22

I would take a guess that Lotus Notes would expect data that's Automation Compatible. My best guess would be that since AHK_L has true arrays it might be easier to pass the info with it. I'd ask Lexicos for advice.

If not that then you might be able to load a memory buffer in a way Lotus Notes can see as an expected data type. Check the params for the method calls to get a clue what it wants the IN param to be.
"My plan is to ghostwrite my biography. Then hire another writer to put his
name on it and take the blame."

- MilesAhead

EagleKen
Posts: 3
Joined: 18 Oct 2013, 10:48

Re: COM programming issues

Post by EagleKen » 18 Oct 2013, 17:37

MilesAhead wrote:I would take a guess that Lotus Notes would expect data that's Automation Compatible. My best guess would be that since AHK_L has true arrays it might be easier to pass the info with it. I'd ask Lexicos for advice.

If not that then you might be able to load a memory buffer in a way Lotus Notes can see as an expected data type. Check the params for the method calls to get a clue what it wants the IN param to be.
Yea, that's the odd part, the Lotus Notes docs (http://publib.boulder.ibm.com/infocente ... ETHOD.html) says that it's looking for an "array of string". so using the

Code: Select all

to := ["email1@server.com","email2@server.ca"]
I thought would have been sufficient, however it doesn't appear to be the case...

I'm not sure if I'm familiar enough with memory buffers to be able to go that route. (although it sounds interesting)..

User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: COM programming issues

Post by jethrow » 18 Oct 2013, 22:31

A native AHK array shouldn't work - but a COM Array (SafeArray) might. Try this:

Code: Select all

to := ComObjArray(0xC,2)
to[0] := "email1@server.com"
to[1] := "email2@server.ca"

lexikos
Posts: 9688
Joined: 30 Sep 2013, 04:07
Contact:

Re: COM programming issues

Post by lexikos » 19 Oct 2013, 19:36

MilesAhead wrote:I'd ask Lexicos for advice.
Lexicos isn't registered on this forum.
jethrow wrote:to := ComObjArray(0xC,2)
If the documentation asks for "array of string", you can replace 0xC (VT_VARIANT) with 8 (VT_BSTR - refer to the type list). However, the documentation says "Type conversion occurs as necessary".

EagleKen
Posts: 3
Joined: 18 Oct 2013, 10:48

Re: COM programming issues

Post by EagleKen » 26 Oct 2013, 16:53

Thanks so much guys, you rock, listing my completed functions (for reference)

Code: Select all


StringSplit(in,delim,omit="") {

	StringSplit, out, in, %delim%, %omit%
	o :=	[]
	Loop %	out0
		o.Insert(out%A_Index%)
	return	o

}

LotusEmail(to, cc, bcc, subject, ebody, attach, test) {

	try {

		if test {
			to := "test@email.com,test2@email.com"
			cc := ""
			bcc := "test3@email.ca"
			subject:="testing!!!!"
		}
			
		notes := ComObjCreate("Lotus.NotesSession")
		notes.initialize()
;		notes.Initialize("<password>") 
		Maildb := notes.GETDATABASE("", "D:\Data\Notes\XXXXXXX.nsf")
		MailDoc := Maildb.CREATEDOCUMENT
		MailDoc.ReplaceItemValue("Form", "Memo")
		
		to := StringSplit(to, "`," , A_Space)
		cc := StringSplit(cc, "`," , A_Space)
		bcc := StringSplit(bcc, "`," , A_Space)

		count1 := to._MaxIndex()
		Lotusto := ComObjArray(VT_VARIANT:=12, count1)

		for index, element in to
		{
			Lotusto[index-1] := element
		}

		count1 := cc._MaxIndex()
		Lotuscc := ComObjArray(VT_VARIANT:=12, count1)
		for index, element in cc 
		{
			Lotuscc[index-1] := element

		}

		count1 := bcc._MaxIndex()
		Lotusbcc := ComObjArray(VT_VARIANT:=12, count1)

		for index, element in bcc 
		{
			Lotusbcc[index-1] := element

		}

		MailDoc.ReplaceItemValue("SendTo", Lotusto)
		
		if (cc) 
			MailDoc.ReplaceItemValue("CopyTo", Lotuscc)			
		if (bcc)
			MailDoc.ReplaceItemValue("BlindCopyTo", Lotusbcc)
		
		MailDoc.ReplaceItemValue("Subject", subject)	
		Body := MailDoc.CREATERICHTEXTITEM("Body")
		Body.APPENDTEXT(ebody)
		
		if (attach) {
			IfExist, %attach% 
				Body.addNewLine(2)
			IfExist, %attach% 
				Body.EMBEDOBJECT(1454, "", attach, "Attachment")
					
		} 
		
		MailDoc.SAVEMESSAGEONSEND := True
		FormatTime, CurrentDateTime, , MM/dd/yyyy HH:mm:ss
; This is to have a copy of the email in the "sent items" folder, doesn't work yet
;		MsgBox The current time and date (date first) is %CurrentDateTime%.
;		MailDoc.ReplaceItemValue("PostedDate", CurrentDateTime)
;		MailDoc.PostedDate(CurrentDateTime)
		MailDoc.SEND(False)

	} catch e {
		MsgBox, 16,, % "Error!`n`nwhat: " e.what "`nfile: " e.file "`nline: " e.line "`nmessage: " e.message "`nextra: " e.extra


		body := ""
		MailDoc := ""
		Maildb := ""
		notes := ""
		
		
	}
}

Post Reply

Return to “Ask for Help (v1)”