Caillte Posted October 2, 2023 Posted October 2, 2023 I stumbled on this function in an effort to streamline sending a list of emails monthly. I noticed that this function does not support CC and BCC. Is this on purpose, or just an oversight? I believe I've found a workaround that remedies the issue, but am not sure where to post that code to get it added in future builds.
Developers Jos Posted October 2, 2023 Developers Posted October 2, 2023 I won't use that UDF anymore when you need anything other than a simple "send email to a local smtp server without security". Use this UDF when you want to do anything else. It is based on the MS "CDO.Message" COM object: SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Caillte Posted October 2, 2023 Author Posted October 2, 2023 My main goal was to make a script that did not require credentials embedded that utilized Outlook that's already running on my machine to send a batch of emails. So, the answer to my first question would be, that's kind of deprecated code and shouldn't be used? Which leads to the second question of, is there a good way to do what I'm trying to do?
taurus905 Posted October 2, 2023 Posted October 2, 2023 Hello Caillte, I haven't tested this, but maybe it you can get it working. taurus905 Local $oOutlook = ObjGet("", "Outlook.Application") ; Get running instance of Outlook If Not IsObj($oOutlook) Then MsgBox(0, "Error", "No running instance of Outlook found.") Exit EndIf Local $oNamespace = $oOutlook.GetNamespace("MAPI") Local $oMailItem = $oOutlook.CreateItem(0) ; olMailItem Local $aRecipients = ["recipient1@example.com", "recipient2@example.com"] ; Add your recipients here For $sRecipient In $aRecipients $oMailItem.Recipients.Add($sRecipient) Next $oMailItem.Subject = "Your Subject" $oMailItem.Body = "Your Message Body" $oMailItem.Send() "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs
Caillte Posted October 3, 2023 Author Posted October 3, 2023 Thanks for the insight, Taurus, but that does not handle the requirement of CC and BCC addresses. I'll take a deeper look at COM as an option, though.
Solution taurus905 Posted October 3, 2023 Solution Posted October 3, 2023 Try this: Local $oOutlook = ObjGet("", "Outlook.Application") ; Get running instance of Outlook If Not IsObj($oOutlook) Then MsgBox(0, "Error", "No running instance of Outlook found.") Exit EndIf Local $oMailItem = $oOutlook.CreateItem(0) ; olMailItem ; Recipient types Global Enum $olTo = 1, $olCC, $olBCC Local $aRecipientsTo = ["recipient1@example.com", "recipient2@example.com"] ; Add your TO recipients here Local $aRecipientsCC = ["cc1@example.com", "cc2@example.com"] ; Add your CC recipients here Local $aRecipientsBCC = ["bcc1@example.com", "bcc2@example.com"] ; Add your BCC recipients here For $sRecipient In $aRecipientsTo $oMailItem.Recipients.Add($sRecipient).Type = $olTo Next For $sRecipient In $aRecipientsCC $oMailItem.Recipients.Add($sRecipient).Type = $olCC Next For $sRecipient In $aRecipientsBCC $oMailItem.Recipients.Add($sRecipient).Type = $olBCC Next $oMailItem.Subject = "Your Subject" $oMailItem.Body = "Your Message Body" $oMailItem.Send() "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now