how to create group email with CDO Using VB6 - vb6

How can I send an email to a group of recipients with CDO? I'm using VB6.

You can list multiple recipients on the .To line by separating them with ";", for example:
Set m = Server.CreateObject("CDO.Message")
m.Subject="subject..."
m.From="sender#example.com"
m.To="some#email.com;other#email.com;third#email.com"
m.TextBody="Message"
m.Send

This works in Office 97 and whatever Exchange we had back then:
Dim oOApp As Outlook.Application
Dim newMail As Outlook.MailItem
Set oOApp = CreateObject("Outlook.Application")
Set newMail = oOApp.CreateItem(olMailItem)
With newMail
.Display
.Body = whatever
.Subject = whatever
.Attachments.Add whatever
.Recipients.Add (whomever)
.Send
End With
Set newMail = Nothing
Set oOApp = Nothing

Related

Open Outlook 2016 with a given non-default profile with VBScript

I have a VBScript which opens Outlook 2016 and sends a message.
The problem I have is that I have several Outlook profiles.
I would like to set the actual profile I wish to open from which to send the message.
My existing script is:
Dim objOutlook, objEmail
Dim strEmailReceiver, strEmailCc, strEmailBcc, strEmailSubject, strEmailBody, strEmailAttachments
Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(0)
strEmailSubject=InPutBox("Input your message")
With objEmail
.To = "here#there.com"
' .Cc = strEmailCc
' .Bcc = strEmailBcc
.Subject = strEmailSubject
' .Body = strEmailBody
' If (strEmailAttachments <> "") Then
' .Attachments.Add strEmailAttachments
' End If
.Send
End With
'Clear the memory
Set objOutlook = Nothing
Set objEmail = Nothing
I wish to use the profile called CEO
If outlook is closed, I get a messagebox asking which profile to use, once selected the script works. This is the step I wish to avoid.
Immediately after creating an instance of the Outlook.Application object, add code like the following
Set objOutlook = CreateObject("Outlook.Application")
set objNS = objOutlook.GetNamespace("MAPI")
objNS.Logon("The Profile name")
Set objEmail = objOutlook.CreateItem(0)
keep in mind that if Outlook is already running, Namespace.Logon will do nothing and you will end up with the running instance of Outlook (since it is a singleton) using whatever profile it was using at the moment

Using Outlook 365 with VB6

We have switched over to office 365 / outlook.
we have a legacy application in VB6 the was working fine with the previous version of outlook. but now we are having issues with an automated email with in VB6, that sends daily reports. Can someone tell me what is the equivalent of the following code is and what reference i need to point to?`
Dim mstrEmailTo As String 'email to addresses
Dim mstrEmailCC As String 'email cc addresses
mstrEmailTo = Text1.Text
mstrEmailCC = "TestEmail"
Dim oApp As Outlook.Application
Dim oCB As Office.CommandBar
Dim oCBTools As Office.CommandBarPopup
Dim oCBSelect As Office.CommandBarButton
Dim oInsp As Outlook.Inspector
Dim oCont As Outlook.MailItem
Set oApp = New Outlook.Application
Dim oInspLeft As Integer
Dim oContTo As String
Dim oContCC As String
Set oCont = oApp.CreateItem(olMailItem)
If mstrEmailTo <> "" Then
'objRecipients.AddMultiple mstrEmailTo, CdoTo
oCont.To = mstrEmailTo
End If
If mstrEmailCC <> "" Then
'objRecipients.AddMultiple mstrEmailCC, CdoCc
oCont.CC = mstrEmailCC
End If
'Set objNewMsg.Recipients = mobjSession.AddressBook(objRecipients, "Select recipients for the Daily report ...", , True, 2)
Set oInsp = oCont.GetInspector
oInsp.Display vbModeless
oInsp.WindowState = olNormalWindow
oInspLeft = oInsp.Left
oInsp.Left = -10000 'Set the Inspector off screen.
'Set to 250 to return it to viewable location
Set oCB = oInsp.CommandBars("Menu Bar")
Set oCBTools = oCB.Controls("&Tools")
Set oCBSelect = oCBTools.Controls("Address &Book...")
oCBSelect.Execute
oContTo = oCont.To
oContCC = oCont.CC
oCont.Close olDiscard
oInsp.Left = oInspLeft
Set oCont = Nothing
Set oCBSelect = Nothing
Set oCBTools = Nothing
Set oCB = Nothing
Set oApp = Nothing`
You don't need to simulate a button click to show an address book. You need to use SelectNamesDialog object for that - see https://learn.microsoft.com/en-us/office/vba/api/outlook.selectnamesdialog

Outlook .Recipients.ResolveAll ambiguous name resolution failure

When resolve all cannot process (due to multiple users on our system with the same first/last name) the macro fails to run. Is there a way to get outlook to display the names and let me select which john doe I want (if not then maybe just remove the names it can't resolve).
Sub Reply_All_From_Folder()
Dim original As MailItem
Dim reply As MailItem
Set original = ActiveInspector.CurrentItem.ReplyAll
Set reply = Application.CreateItem(olMailItem)
With reply
.SentOnBehalfOfName = "folder#work.com"
.Subject = original.Subject
.To = Replace(original.To, "emailoRemove#test.com", "")
.CC = original.CC
.HTMLBody = original.HTMLBody
.Recipients.ResolveAll
.Display
End With
End Sub
You can simulate pressing the Check Names button if ResolveAll is false.
Sub Reply_All_From_Folder_NotResolveAll()
Dim trueoriginal As mailItem
Dim original As mailItem
Dim reply As mailItem
Set trueoriginal = ActiveInspector.currentItem
Set original = ActiveInspector.currentItem.ReplyAll
Set reply = CreateItem(olMailItem)
With reply
.subject = original.subject
.To = original.To & "; notaresolvablename" & "; smith, john"
If Not .Recipients.ResolveAll Then
.Display
ActiveInspector.CommandBars.ExecuteMso ("CheckNames")
Else
.Send
End If
End With
trueoriginal.Close olDiscard
ExitRoutine:
Set trueoriginal = Nothing
Set original = Nothing
Set reply = Nothing
End Sub

Sending emails to multiple recipients using vbscript

My vbscript sends email to automatically to a recipient, but does anyone know how to add more than one recipient to it?
...
Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MyTime
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
MyTime = Now
ToAddress = "email#address.com"
MessageSubject = "It works!."
MessageBody = "Good job on that script."
MessageAttachment = some attachment
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf & MyTime
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send
This is what I have right now. And it works fine. But, I'd like to have more than one recipients. Thanks in advance.
newMail.CC = "person1#domain1.org;person2#domain2.org;person3#domain3.org"
This above line worked!
And it works the same way with .BCC, in case anyone wants to not to display the contacts' list.
Call MailItem.Recipients.Add for each recipient or set the To/CC/BCC properties to a ";" separated list of addresses.

How to send email to a distribution list with vbScript in an asp

I'm very new to vbscript but here's what I have so far, Doesn't seem to be working though:
<script type="text/vbscript">
Sub Senmail()
Dim objOutlook As Object
Dim objOutlookMsg As Object
Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(0)
With objOutlookMsg
.To = "eric#gmail.com"
.Cc = "name#email.com"
.Subject = "Hello World (one more time)..."
.Body = "This is the body of message"
.HTMLBody = "HTML version of message"
.Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
</script>
Any input would be appreciated! Or any other ways I could send an email is my asp....
Here's one way using CDO / SMTP
Sub SendMail()
Set objMsg = CreateObject("CDO.Message")
Set objConfig = CreateObject("CDO.Configuration")
Set objFields = objConfig.Fields
With objFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "YourSMTPServer"
.Update
End With
With objMsg
Set.Configuration = objConfig
.To = "eric#gmail.com"
.CC = "name#gmail.com"
.From = "you#gmail.com"
.Subject = "Hello World"
.HTMLBody = "This is the body of message"
.Fields.Update
.Send
End with
Set objMsg = Nothing
Set objConfig = Nothing
End Sub
For starters, remove the As Object from your Dim statements. In VBScript, you can't declare variables As any particular data type. Everything's a variant.
Dim objOutlook
Dim objOutlookMsg
If you want more help, then you may want to tell us something more specific about your problem than "Doesn't seem to be working" e.g. what error or wrong behaviour you are getting.

Resources