Doug Barnes
doug at starntech.com
Tue Sep 23 08:13:44 CDT 2008
Here's a snippet of code we use in a vbs script file to send emails with an
importance and priority set:
strRecords = "Record Count: " & lngCount & "<br>" & strRecords
strSubject = "Status"
strVendorEmail = "doug at starntech.com"
'Create body of email
htmlEmail = "<html><head><title>" & strSubject & "</title>"
htmlEmail = htmlEmail & "<style>"
htmlEmail = htmlEmail & "h1{font-family : Arial; font-size : 16pt;
font-weight : bold; color: #000000;}"
htmlEmail = htmlEmail & "p{font-family : Arial; font-size : 10pt;
color: black; text-align : justify;}</style></head>"
htmlEmail = htmlEmail & "<body bgcolor='#ffffff'>"
htmlEmail = htmlEmail & "<p>" & strRecords & "</p>"
htmlEmail = htmlEmail & "</body></html>"
'Use CDOSYS to send email
'Create CDO.Message Object
Set myMail = WScript.CreateObject("CDO.Message")
'Set up the email header
myMail.Subject = strSubject
myMail.From = strFromEmail
myMail.To = strVendorEmail
myMail.HTMLBody = htmlEmail
'Set the configuration settings
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/con
figuration/smtpauthenticate") = cdoBasic
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/con
figuration/sendusername")="cdomail"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/con
figuration/sendpassword")="Cd0Ma1l"
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/con
figuration/sendusing")=gintSendUsing
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/con
figuration/smtpserver")=gstrSMTPServer
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/con
figuration/smtpserverport")=gintSMTPPort
myMail.Configuration.Fields.Update
myMail.Fields("urn:schemas:httpmail:importance") = 2 ' drb 08/16/07
set importance
myMail.Fields("urn:schemas:mailheader:X-Priority") = 2 ' drb
08/16/07
myMail.Fields.Update ' drb 08/16/07 need to save the values
'Send the email
myMail.Send
'Clear the CDO.Message object
set myMail = nothing
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com]On Behalf Of Jim Dettman
Sent: Tuesday, September 23, 2008 8:46 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] CDO/Priority flag.
Joe,
I'll give that a shot. I know for sure already that there is no space in
there. Everything past the first address is ignored for the To, CC, and
BCC, so it's something I doing.
I'll let you know if it works.
Thanks,
Jim.
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Joe O'Connell
Sent: Friday, September 19, 2008 11:20 PM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] CDO/Priority flag.
Jim,
Try putting a space after the semi-colon for multiple recipients.
Joe O'Connell
-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jim Dettman
Sent: Friday, September 19, 2008 1:12 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] CDO/Priority flag.
All,
This seems like it should be simple, and yet an internet search turns
up a
variety of answers, none of which seems to work. I've never worked with
CDO
before, but have instead preferred to use vbSendMail, but I have a
client
that wants to go with CDO as that's what is being used with the rest of
the
apps they already have.
This is a simple "send an e-mail" based on a table utility. Two
things
don't seem to be working right; multiple recipients and setting a
priority
flag.
For the multiple recipients, I'm using a semi-colon delimited list.
For
the priority flag, I've tried it as part of the configuration setting
and as
a change to the message fields (I get an error with this method about
being
disconnect from the client and Access then hangs at exit).
Can't believe I've spent the amount of time I have on something that
should be so simple.
Anyone got any insight on this? Code is below.
Jim.
Public Sub DoEmailTask(strTaskName As String)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim strMsg As String
Dim objMessage As Object
On Error GoTo DoEmailTask_Error
Set db = CurrentDb()
strSQL = "SELECT * FROM tblEmailTasks WHERE [EmailTaskName] = '" &
strTaskName & "'"
Set rst = db.OpenRecordset(strSQL)
If rst.RecordCount = 0 Then
' Task name not in table
strMsg = "Mail task name '" & strTaskName & "' was not found in
tblEmailTasks."
MsgBox strMsg, vbCritical + vbOKOnly, "Invalid e-mail task name"
Else
With rst
' Send the e-mail
Set objMessage = CreateObject("CDO.Message")
' Don't rely on configuration settting on client
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/c
onfi
guration/sendusing") = !SendUsing
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/c
onfi
guration/smtpserver") = !SMTPServer
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/c
onfi
guration/smtpauthenticate") = !SMTPAuthenticate
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/c
onfi
guration/sendusername") = !SendUserName
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/c
onfi
guration/sendpassword") = !SendUserPassword
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/c
onfi
guration/sendusing") = !SendUsing
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/c
onfi
guration/smtpserverport") = !SMTPPort
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/c
onfi
guration/smtpusessl") = !UseSSL
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/c
onfi
guration/smtpconnectiontimeout") = !ConnectTimeout
'objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/
conf
iguration/priority") = !priority
objMessage.Configuration.Fields.Item("urn:schemas:mailheader:X-MSMail-Pr
iori
ty") = 0
objMessage.Configuration.Fields.Update
Stop
objMessage.From = !From
objMessage.To = !To
objMessage.CC = !CC
objMessage.BCC = !BCC
objMessage.Subject = !Subject
objMessage.TextBody = !Message
objMessage.Send
End With
End If
DoEmailTask_Exit:
Set objMessage = Nothing
If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If
Set db = Nothing
Exit Sub
DoEmailTask_Error:
Resume DoEmailTask_Exit
End Sub
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com