Problem sending email with CDO, SMTP. Get Update Fields err

I think I’ve read every post on the subject but I’ve yet to find a solution. I’m trying to send email via SMTP using CDO (CDOSYS) on our Win2000 server. I can schedule the document to refresh with BCA and it creates the HTML file beautifully, but I haven’t read anything that points me in the right direction on my error message. Can anyone shed some light as I am stuck like Chuck :confused: - thanks

I get the following error:

“Error in procedure Document_AfterRefresh – 3749: Fields update failed. For further information, examine the Status property of individual field objects. (ADODB.Fields)”

Here’s the code:

Private Sub Document_AfterRefresh()
Const OUTPUT_DIRECTORY As String = "D:\BOTest"
Const ERR_MSG_PATH As String = "D:\BOTest\ErrorLogs"

Dim DocOpen As Integer
Dim Docname As String
Dim doc As IDocument
Dim rpt As Report

Dim SavHtmname As String

DocOpen = 1
LogOpen = 0

On Error GoTo ErrHandler

Set doc = ActiveDocument
Set rpt = ActiveReport
Docname = ActiveDocument.Name

'Export HTML file
SavHtmname = OUTPUT_DIRECTORY & "\" & Docname & ".htm"
Call rpt.ExportAsHtml(SavHtmname, 1, 1, 1, 1, 1, 1, 1, 0, 0)

Dim iMsg
Dim iConf
Const cdoSendUsingPort = 25

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

Set Flds = iConf.Fields

With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "<10.0.1.10>"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
    .Update   ' <------ My problem is here but not sure why.
End With

'Send email with attachment
With iMsg
   Set .Configuration = iConf
    .To = "me@company.com"
   .From = "me@company.com"
   .Subject = "an example mhtml formatted message"
   .AddAttachment SavHtmname
   .Send
End With

Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

ForceExit:
Exit Sub

ErrHandler:

'******
    lngFileNum = FreeFile()
    strLogFileName = ERR_MSG_PATH &amp; "\" &amp; ActiveDocument.Name &amp; "-ErrorMessages.Log"
    strLogMsg = "Error in procedure Document_AfterRefresh -- " &amp; Err.Number &amp; ": " _
        &amp; Err.Description &amp; " (" &amp; Err.Source &amp; ")"
        
    Open strLogFileName For Append As #lngFileNum
    Write #lngFileNum, Now(), strLogMsg
    Close #lngFileNum
        
    '*** This "Resume" statement resets the error and allows your procedure to exit cleanly.
    Resume ForceExit

'******

End Sub

[Edit - Please use the “Code” formatting option when posting code samples. It preserves the indenting and makes the post easier to read. Thanks. - Dave]


SeanB (BOB member since 2004-02-11)

Dim Cfg As CDO.Configuration
Set Cfg = New CDO.Configuration
Cfg.Fields(cdoSendUsingMethod) = cdoSendUsingPort
Cfg.Fields(cdoSMTPServer) = "smtp.domain.com"
Cfg.Fields.Update

I use the code above. The syntax is a little cleaner, but I don’t think that alone is causing your issue. My suspicions would be whether the IP address should be in angle brackets … “<10.0.1.10>” vs “10.0.1.10” … and whether the timeout is numeric or a string … 10 vs “10”. I haven’t researched or tested those. I would suggest adding them one at a time as a debugging method.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Below article might help you

http://www.microsoft.com/technet/treeview/default.asp?url=/technet/scriptcenter/default.asp


JaiGupta (BOB member since 2002-09-12)

I use http://msdn.microsoft.com/library/default.asp?url=/library/en-us/exchanchor/htms/msexchsvr_cdowin2000.asp?frame=true as my reference. I had a moment to look, and the timeout is indeed a numeric property, so I would try leaving the angle brackets off the ip address.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

Thanks.

I’ve tried using this without the Timeout parameter but still get the same error. I’ve also tried removing the angle brackets around my IP address but get the same error.

.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mysmtp.domain.com"
 

Does the BCA need specific rights to create CDO objects on the server?


SeanB (BOB member since 2004-02-11)

Does it work on your workstation manually (not via BCA)? I usually get things working that way first.


Dwayne Hoffpauir :us: (BOB member since 2002-09-19)

We were experiencing a similar issue and a member my team switched our email script over to mimic an example from this board and it works wonderfully but for me.

The code:

Cfg.Fields(cdoSendUsingMethod) = cdoSendUsingPort
Cfg.Fields(cdoSMTPServer) = “myserver.mycompany.com
Cfg.Fields.Update

Causes me to get a Error Loading dll (Error “48”) and I am out of ideas.
The cdoex.dll is in the path listed. Since I stopped coding about 7 years ago (Do just DBA functions now) I have not a clue where to begin.
Anybody have an Idea?


tzirbel (BOB member since 2003-02-19)

The problem is that you are setting .Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = cdoSendUsingPort and you have declared cdoSendUsingPort = 25.

The valid values for that item are 1 (CDO.cdoSendUsingPickup), 2 (CDO.cdoSendUsingPort), and 3 (CDO.cdoSendUsingExchange).

If you want to use an alternate smtp port, you would use this syntax:
.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = cdoSendUsingPort

I realize this post is over 2 years late, but I was getting the same error and thought that it would be nice to find the answer on this page.


Slider (BOB member since 2006-02-09)

I am having a similar problem, except that I am using Access and need to send several emails from a list in a table. I can get the code to send ONE email, but when it loops back I get error message at the .Update line. Also, I used to be able to send the emails to my draft folder in Outlook and review them one more time before I send them. Can that be done with gmail?

Here is the code I am trying to use.

Private Sub CmdSendLateNoticeTest_Click()
DoCmd.SetWarnings False
DoCmd.OpenQuery “q21c_Lateemail_UpdateAccountingComments”
DoCmd.OpenQuery “q21_UpdateLateAccounting”
DoCmd.RunMacro “m_BuildLate_Email_temp”

Dim Mydb As Database
Dim MyRS As DAO.Recordset
Dim imsg As Object
Dim StrBody As String
Dim iConf As Object
Dim Flds As Variant
Dim TheAddress As String
Dim MyRS2 As DAO.Recordset
Dim MyRS3 As DAO.Recordset
Dim PLAN_TYPE As String
Dim PLAN_NAME As String

Set imsg = CreateObject(“CDO.Message”)
Set iConf = CreateObject(“CDO.Configuration”)
Set Mydb = CurrentDb
Set MyRS = Mydb.OpenRecordset(“tempLate_email”)
MyRS.MoveLast
MyRS.MoveFirst
'Set MyRS2 = Mydb.OpenRecordset(“tEmailCCList”)
TheAddress = MyRS![contact_email] & "; " & MyRS![wc_email]

Do Until MyRS.EOF
’ Create the e-mail message.
TheAddress = MyRS![contact_email_txt] & "; " & MyRS![wc_email] & "; " & MyRS![RiverOps_Email]
PLAN_TYPE = MyRS![PLAN_TYPE]
PLAN_NAME = MyRS![PLAN_NAME]
Set MyRS3 = Mydb.OpenRecordset(“emailReferences”)

iConf.Load -1    ' CDO Source Defaults
Set Flds = iConf.Fields
   With Flds
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "me@yyyy.xxx"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "xxxxx"
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
    .Update - this is where I get the error on the second message
 End With

With imsg
Set .Configuration = iConf
.To = TheAddress
.CC = " "
.BCC = " "
.From = “”“My Name”" me@xxxx.com"

.Subject = "LATE NOTICE " & Forms![f1c_LateLetters]![Monthname] & " Monthly Accounting " & [PLAN_NAME]

Select Case PLAN_TYPE
Case “AUG”
.TextBody = ""this is the text for aug plans. "
Case “MUN”
.TextBody = "this is the text for muns. "
Case “PIT”
.TextBody = "this is the text for pits. "
Case “SWSP”
.TextBody = "this is the text for swsps. "

End Select

    .Send
  End With
  MyRS.MoveNext

Loop
Set imsg = Nothing
Set iConf = Nothing
Set Flds = Nothing

End Sub


kattrask (BOB member since 2012-10-17)