Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2005

    Unanswered: Using SMTP From Access


    I am having a terrible time trying to send SMTP mail from access using a remote SMTP server. The CDO library allows for it with the code posted below. All of my settings are correct. I have tested this on multiple servers with multiple accounts and I receive this error:

    Message was not sent to: Error in sending. The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available.
    Please don't respond if you are going to tell me that my password, user, or smtp server address are incorrect

    Here is the standard code I am using. You can find it anywhere.

    Public Sub RunSendEmailsFromConsoleSMTP()

    Dim iCfg As Object
    Dim iMsg As Object

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

    With iCfg.Fields
    .Item("") = pubEmailServer

    .Item("") = 25
    .Item("") = 2
    .Item("") = 1
    .Item("") = pubEmailSenderName
    .Item("") = pubEmailSendAddress
    .Item("") = pubEmailPassword

    End With


    With iMsg
    .Configuration = iCfg
    .Subject = "Subject"
    .to = ""
    .TextBody = "MessageBody"
    '.AddAttachment "FullPathToAttachment"
    End With

    Set iMsg = Nothing
    Set iCfg = Nothing

    End Sub
    Does this code work for you? Any help would be appreciated... Thanks

  2. #2
    Join Date
    Nov 2007
    Adelaide, South Australia
    I have used that code before. Yes, it works fine.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!

    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Sep 2007
    Global Village
    if you delete the
    PHP Code:
    .Item("") = 
    line then it works or you can use this code which I found in Old threads which is better and doesnt require user email password:
    Public Sub SendEmailCDO() (ByVal strTo As String, ByVal strMessage As String, ByVal strSubject As String, _
    Optional ByVal strAttach As String)
    Dim objEmail As Object
    On Error Resume Next
    Set objEmail = CreateObject("CDO.Message")
    objEmail.FROM = "StrSenderAddress"
    objEmail.To = strTo
    objEmail.Subject = strSubject
    objEmail.TextBody = strMessage
    If strAttach <> "" Then objEmail.AddAttachment strAttach
    objEmail.Configuration.Fields.Item("") = 2
    objEmail.Configuration.Fields.Item("") = ""
    objEmail.Configuration.Fields.Item("") = 25
    '_________________________________________________ ___
    '++Comment out Authentication++
    'objEmail.Configuration.Fields.Item("") = 1
    'objEmail.Configuration.Fields.Item("") = pubEmailPassword
    '_________________________________________________ ___
    If Err.Number <> 0 Then
    MsgBox "Error in sending. " & Err.Description
    MsgBox "Sent"
    End If
    Set objEmail = Nothing
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts