Send email with High Importance using Access

gold007eye

Registered User.
Local time
Today, 10:19
Joined
May 11, 2005
Messages
260
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:
Code:
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?
 
Before the "With iMsg" section of code, insert the following lines:

For Outlook:
Code:
With iMsg.Fields 
    .Item(cdoImportance) = cdoHigh
    .Item(cdoPriority) = cdoPriorityUrgent
    .Update 
End With

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

See if this works for you.
 
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:
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?
 
You are using the wrong object. You want to use the IMsg object.
 
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 :)
 
gold007eye, apparently you need things spelled out for you. Here is your code as it should read (note the highlighted text):
Code:
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.
[b]
With iMsg.Fields 
    .Item(cdoImportance) = cdoHigh
    .Item(cdoPriority) = cdoPriorityUrgent
    .Update 
End With
[/b]
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 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."
 

Attachments

  • Error3001.JPG
    Error3001.JPG
    95.7 KB · Views: 313
Why are you putting it like this:
Code:
With iMsg.Fields
I would think it should be for the whole message
Code:
With iMsg
 
boblarson said:
Why are you putting it like this:
Code:
With iMsg.Fields
I would think it should be for the whole message
Code:
With iMsg

Bob,

I tried it that way in the beginning and it didn't work :confused:
 
You may not have the correct references set. Try this instead:
Code:
With iMsg.Fields 
    .Item("urn:schemas:httpmail:importance") = 2
    .Item("urn:schemas:httpmail:priority") = 1
    .Update
End With
 
This is how I used to do it when working with outlook

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

Code:
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
 
Last edited:
ByteMyzer said:
You may not have the correct references set. Try this instead:
Code:
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)
 

Users who are viewing this thread

Back
Top Bottom