Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

CDO COM - Email Delivery [AHK_L]


  • Please log in to reply
66 replies to this topic
sinkfaze
  • Moderators
  • 6367 posts
  • Last active:
  • Joined: 18 Mar 2008

...I wonder why Sean didn't post it on the first page of the original one!


Probably because we had no way to anticipate that AHK_L would suddenly become the de facto version of AHK. Since at the time the original version was still the standard there wasn't a lot of point to pushing solutions to an alternate version to the top of the stack (an exception being COM).

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

I wonder why Sean didn't post it on the first page of the original one!

IMO, threads like this one should be trivial/pointless. Otherwise, there would've been no point of implementing Native COM.

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006

I wonder why Sean didn't post it on the first page of the original one!

IMO, threads like this one should be trivial/pointless. Otherwise, there would've been no point of implementing Native COM.


I would like to very humbly mention here that experts/programmers who know Objects/COM may find it very trivial. But noobs like me with no programming/engineering background rely on examples. And without any working examples on how to use native COM, it is pretty useless to me.
So I created a thread so that new members of the AHK community are not confused when they try to run scripts on the forum and keep on getting error messages. It is important more so now, becuase AHK_L is the first download option presented to new entrants, and many of the advanced scripts on this forum wont run on AHK_L.

Also, though completely off topic, i would like to mention here that though i joined on 15 Sep 2006, i have not asked many questions on Ask for help all these years. Most of whatever I have learnt in AHK was through studying the Documents (so well written), the examples on the forum, rarely the Wiki. Hence thanks to all active members like Sean and countless others who have created a huge database of useful functions and scripts.
Hence I feel i should do my bit to help any other newbie non-programmer who happens to stumble upon AHK. If this thread is trivial, mods may delete it, as simple as that.

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009

I would like to very humbly mention here that experts/programmers who know Objects/COM may find it very trivial. But noobs like me with no programming/engineering background rely on examples. And without any working examples on how to use native COM, it is pretty useless to me.

+1 Thanks shajul. Your examples are very helpful to me and I'm sure for other non-advanced users too.

SKAN fan
  • Guests
  • Last active:
  • Joined: --

IMO, threads like this one should be trivial/pointless. Otherwise, there would've been no point of implementing Native COM.


I totally disagree. Being Guru doesn't mean your always right, not everyone on the forum is professional programmer, most are noobs.
And some Gurus here realize that (Like SKAN), they try to make things as clear and easy to understand/access as possible. And they don't mind speaking noobs languages once in a while.
However, other gurus seem to demand extra respect and bigger brains of those who want to use their work. And don't even like it when others try to simplify things around.
If you were so concerned about this "Email Delivery" then you would have fixed it on the first page of the original post, I'm not going to browse 11+ pages looking for a version that works
or and update, that's not professional, so be thankful that someone fixed it in a new thread.

Relax dude.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

I would like to very humbly mention here that experts/programmers who know Objects/COM may find it very trivial.

It was not a critique on your thread, but was my answer to the quest.

But noobs like me with no programming/engineering background rely on examples. And without any working examples on how to use native COM, it is pretty useless to me.

That's why I said that Native COM implementation would've been pointless. Why do you think other people were so obsessed with the dot syntax support for COM? Then, countless codes in VBS/JS abundant all over the web were supposed to be example codes, after obvious/trivial adjusts into AHK. Anyway, what count are the contents the codes contain, not the syntax in which they are written. IMO, you better spend your time in digging into/out new contents than in converting mere syntax (which I don't think deserves a new thread).

New AHK experimenter
  • Guests
  • Last active:
  • Joined: --
I have tried to run this using AHK_L but does not work.

Line 30 is "field,value in fields"

and this is the error msg:

D:\1\atest.ahk (30) : ==> This line does not contain a recognized action.
Specifically: For field,value in fields

Any ideas why this does not work?

ruespe
  • Members
  • 567 posts
  • Last active: Dec 01 2014 07:59 PM
  • Joined: 17 Jun 2008
I think, you've got the wrong version of AHK_L. Download the actual one.

New AHK experimenter
  • Guests
  • Last active:
  • Joined: --
Thanks ruespe for repling

Tried Basic, first

I downloaded the latest version. (from the forums Download page)
Installed both ANSI, no luck, then installed the Unicode version (both 32 bit)

But still have the same error.

So I do not think that is the problem, unliess I do not understand
"Download the actual one" means.

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006

IMO, you better spend your time in digging into/out new contents than in converting mere syntax..


I hope List Running Processes [AHK_L], WMI Tasks COM with AHK_L, Create a scheduled task natively [AHK_L] and Powerpoint.application qualify.
CDO email delivery was the first one i used, hence posted it in a new thread so that it was prominent for AHK_L users, with full credits to you. Thanks again for your code. Maybe we can append the posts here to the main thread when we have more powerful moderation features of PHPBB3 8)


But still have the same error.

Steps to get it right:
1. Uninstall current version of Autohotkey
2. Open task manager and "End Process" any Autohotkey.exe process
3. Download and Install Autohotkey_L from here -> Downloads
4. Choose Unicode when prompted.
5. Save the following code as test.ahk and run it
isUnicode := A_IsUnicode ? "Yes" : "No"
MsgBox % "Autohotkey Version : " . A_AhkVersion . "`nAutohotkey Path : " . A_AhkPath . "`nIs Unicode : " . isUnicode

It should say something like

Autohotkey Version : 1.0.90.00
Autohotkey Path : C:\Program Files\AutoHotkey\AutoHotkey.exe
Is Unicode : Yes

Then you can try to run the CDO Email code again. Also, you may want to see Autohotkey_L and Basic Together

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

I hope List Running Processes [AHK_L], WMI Tasks COM with AHK_L, Create a scheduled task natively [AHK_L] and Powerpoint.application qualify.
CDO email delivery was the first one i used, hence posted it in a new thread so that it was prominent for AHK_L users, with full credits to you.

Good. BTW, if you're interested in a real challenge on Email subject, here is one: although I haven't encountered one so far, there is a possibility that some smtp server accepts only 587 port for Explicit SSL. As CDOSYS doesn't handle 587 port for Explicit SSL, there may remain only one COM solution: using .NET's System.Net.Mail. So, write a COM code for it. If you like a pure COM challenge, here is another one: write a COM code for 465 port for Implicit SSL using System.Web.Mail, which will be a little more involved.

The Naked General
  • Members
  • 21 posts
  • Last active: Jan 27 2012 02:41 AM
  • Joined: 22 Feb 2009
Absolutely great work guys!

I have had a need over the last week or so to hook an Outlook box to send messages. I'm still working on it but I figured I'd post what I have so far as I tore the forums apart looking for something like it. Parts are based on the CDO.message functions and most of the rest was modified from the Outlook developer site here:
<!-- m -->http://msdn.microsof...y/ff861252.aspx<!-- m -->

I'm still working on CC and BCC and MAPI uses some kind of crazy account struct for the from field, so... yeah. But the attachments work and it resolves the "to" address before sending and alerts you if it won't resolve.

DEPENDENCIES:
This script requires that Outlook or another MAPI based mail client be installed

It is written in AHK_L COM compliant syntax

TEST ENVIRONMENT:
Built and tested in Windows XP X64 sp3 with a gmail account. Written with SciTE4AHK


object.FromAddress := "noreply@gmail.com"
ToAddress := "noreply@gmail.com"
MessageSubject := "MAPI TEST"
MessageBody := "This is a test of the MAPI hooked batch sender"
AttachmentPath := "c:\TEST.txt|c:\OTHER_TEST.ico" ; can add multiple attachments, the delimiter is |

ol := ComObjCreate("Outlook.Application")
ns := ol.getNamespace("MAPI")
ns.logon("","",true,false) ;get default MAPI profile
newMail := ol.CreateItem(0) ;0 is Outlook constant 'olMailItem' (thanks Sinkfaze)
newMail.Subject := MessageSubject
newMail.Body := MessageBody
MessageAttach := newMail.Attachments
Loop, Parse, AttachmentPath, |, %A_Space%%A_Tab%
MessageAttach.Add(A_LoopField)

; validate the recipient, just in case...
myRecipient := ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved
MsgBox "unknown recipient"
Else
{
newMail.Recipients.Add(myRecipient)
;newMail.Sender := FromAddress ;this would be the from field but does not work yet
newMail.Send
MsgBox mail sent!
}
Return

Improvements are welcome!
"lol, i made this thing, but it didn't work... so I read the forums and now it does!"

New AHK experimenter
  • Guests
  • Last active:
  • Joined: --
yes, yes, yes

At last, although a little dismayed at the steps, but it finally worked.
This will teach me for future use.


thx to shajul

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006

DEPENDENCIES:
This script requires that Outlook or another MAPI based mail client be installed

It is written in AHK_L COM compliant syntax

TEST ENVIRONMENT:
Built and tested in Windows XP X64 sp3 with a gmail account. Written with SciTE4AHK

Your documentation is wonderful, covers all aspects, something for us to imitate.


object.FromAddress := "noreply@gmail.com"
...
;newMail.Sender := FromAddress ;this would be the from field but does not work yet


The reason the from field does not work maybe because the from field need not be an object, eg (this works for me)
FromAddress := "noreply@gmail.com"
...
newMail.Sender := FromAddress


ns.logon("","",true,false) ;get default MAPI profile

This may be changed to
ns.logon("Outlook","",true,true) ;get default MAPI profile
as that is the default profile created by Outlook.

The Naked General
  • Members
  • 21 posts
  • Last active: Jan 27 2012 02:41 AM
  • Joined: 22 Feb 2009
Yeah I tried it like you said above not referencing it as a object and it throws an error.

Tested on two machines now with same error.

Error: 0x80020006 - Unknown name.

Specifically: Sender

025: newMail.Sender := FromAddress
"lol, i made this thing, but it didn't work... so I read the forums and now it does!"