View Full Version : Send email with High Importance using Access


gold007eye
01-12-2007, 07:16 AM
Is there any code that will allow me to send an e-mail as "High Priority / High Importance" through Access?

Here is the code I am using currently:

Private Sub Save_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Dim mail
Set mail = Nothing
' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML

Const cdoSendUsingPort = 2

'==== A/R 60 Code Start ====
ElseIf Me![A/R Code] = "60" Then

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields
' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "usahm204.amer.corp.eds.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Update
End With
' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "This is an automated e-mail to let you know that <b><font color=#FF0000>" & [Name of Requestor] & "</b></font> from <b><font color=#FF0000>" & [Department of Requestor] & "</b></font> has submitted a new <b><font color=#FF0000>A/R " & [A/R Code] & "</b></font> request in PERD."
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"
' Apply the settings to the message.
With iMsg
Set .Configuration = iConf
.To = "<Carol.Patukonis@examhub.exch.eds.com>" 'ToDo: Enter a valid email address.
.Cc = "<Elisa.Chandler@examhub.exch.eds.com>;<Deborah.Davis@examhub.exch.eds.com>"
.Bcc = "<Carlene.Vitello@examhub.exch.eds.com>;<Jason.Boney@examhub.exch.eds.com>"
.From = "PERD Request<Jason.Boney@eds.com>" 'ToDo: Enter a valid email address.
.Subject = "New A/R " & [A/R Code] & " Request"
.HTMLBody = strHTML
.Send
End With
' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
'==== A/R 60 Code End ====


I have tried using .Priority = "High" and .Importance = "High", but I keep getting an error stating this object property is invalid. What can I use to set a priority (Low, Normal, High) on the e-mail using the above code?

ByteMyzer
01-12-2007, 09:28 AM
Before the "With iMsg" section of code, insert the following lines:

For Outlook:

With iMsg.Fields
.Item(cdoImportance) = cdoHigh
.Item(cdoPriority) = cdoPriorityUrgent
.Update
End With


For Outlook Express:

With iMsg.Fields
.Item("urn:schemas:mailheader:X-Priority") = 1
.Update
End With


See if this works for you.

gold007eye
01-12-2007, 10:32 AM
I was getting hopeful. I what you said. but I keep getting the error:
"Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

Here is where I put the code:

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields
' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "usahm204.amer.corp.eds.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Item(cdoImportance) = cdoHigh
.Item(cdoPriority) = cdoPriorityUrgent
.Update
End With


I will try messing around and see if I can get it to work. Any other suggestions? maybe instead of =cdoHigh would you just use a number?

KeithG
01-12-2007, 11:33 AM
You are using the wrong object. You want to use the IMsg object.

gold007eye
01-12-2007, 11:57 AM
Is there anyway you can show me an example using my code where to put this code. I tried putting the code under the With iMsg section. I tried it before .To = code and also after the .Subject = code. Then it tells me "Object doesn't support this property or method" Please help :)

ByteMyzer
01-12-2007, 12:02 PM
gold007eye, apparently you need things spelled out for you. Here is your code as it should read (note the highlighted text):

Private Sub Save_Click()
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Dim mail
Set mail = Nothing
' Send by connecting to port 25 of the SMTP server.
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML

Const cdoSendUsingPort = 2

'==== A/R 60 Code Start ====
ElseIf Me![A/R Code] = "60" Then

Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

Set Flds = iConf.Fields
' Set the CDOSYS configuration fields to use port 25 on the SMTP server.
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
'ToDo: Enter name or IP address of remote SMTP server.
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "usahm204.amer.corp.eds.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
.Update
End With
' Build HTML for message body.
strHTML = "<HTML>"
strHTML = strHTML & "<HEAD>"
strHTML = strHTML & "<BODY>"
strHTML = strHTML & "This is an automated e-mail to let you know that <b><font color=#FF0000>" & [Name of Requestor] & "</b></font> from <b><font color=#FF0000>" & [Department of Requestor] & "</b></font> has submitted a new <b><font color=#FF0000>A/R " & [A/R Code] & "</b></font> request in PERD."
strHTML = strHTML & "</BODY>"
strHTML = strHTML & "</HTML>"
' Apply the settings to the message.

With iMsg.Fields
.Item(cdoImportance) = cdoHigh
.Item(cdoPriority) = cdoPriorityUrgent
.Update
End With

With iMsg
Set .Configuration = iConf
.To = "<Carol.Patukonis@examhub.exch.eds.com>" 'ToDo: Enter a valid email address.
.Cc = "<Elisa.Chandler@examhub.exch.eds.com>;<Deborah.Davis@examhub.exch.eds.com>"
.Bcc = "<Carlene.Vitello@examhub.exch.eds.com>;<Jason.Boney@examhub.exch.eds.com>"
.From = "PERD Request<Jason.Boney@eds.com>" 'ToDo: Enter a valid email address.
.Subject = "New A/R " & [A/R Code] & " Request"
.HTMLBody = strHTML
.Send
End With
' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
'==== A/R 60 Code End ====

gold007eye
01-12-2007, 12:41 PM
I had actually tried that as well. I just copied and pasted verbatim "what the code should read" and I am still get the error: Runtime Error: 3001 "Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."

boblarson
01-12-2007, 12:46 PM
Why are you putting it like this:

With iMsg.Fields

I would think it should be for the whole message

With iMsg

gold007eye
01-12-2007, 12:53 PM
Why are you putting it like this:

With iMsg.Fields

I would think it should be for the whole message

With iMsg


Bob,

I tried it that way in the beginning and it didn't work :confused:

ByteMyzer
01-12-2007, 02:20 PM
You may not have the correct references set. Try this instead:

With iMsg.Fields
.Item("urn:schemas:httpmail:importance") = 2
.Item("urn:schemas:httpmail:priority") = 1
.Update
End With

Dreamweaver
01-12-2007, 04:42 PM
This is how I used to do it when working with outlook

Rowsource Of Combo: 1;"High Importance";2;"Low Importance";3;"Normal Importance"


Dim m_ObjOutlook As New Outlook.Application
Dim m_objMessage As MailItem

'Check Format of Mailing Address
Set m_objMessage = m_ObjOutlook.CreateItem(olMailItem)
With m_objMessage
.To = Me![MailTo]
If Not IsNull(Me![MailCc]) Then
.cc = Me![MailCc]
End If
Select Case Me![Priority]
Case 1
.Importance = olImportanceHigh
Case 2
.Importance = olImportanceLow
Case Else 'If Nothing Selected User Gets This
.Importance = olImportanceNormal
End Select
.Subject = Me![Subject]
.Body = strBody
If HasAtt = True Then
'Set Attachments Back to first Record for each new Message loop
recAtt.MoveFirst
While Not recAtt.EOF
strAtt = recAtt("Attachment")
chkAtt = adhFileExists(strAtt) 'Check Just To Make Shore
If chkAtt = True Then
.Attachments.Add (strAtt)
End If
recAtt.MoveNext
Wend
End If
.Send

Hope It Helps

Mick

gold007eye
01-17-2007, 06:59 AM
You may not have the correct references set. Try this instead:

With iMsg.Fields
.Item("urn:schemas:httpmail:importance") = 2
.Item("urn:schemas:httpmail:priority") = 1
.Update
End With


Thanks ByteMyzer! That did the trick perfectly :D (adding this one to my code book)