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

    Unanswered: Using SMTP From Access

    Hi,

    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("http://schemas.microsoft.com/cdo/configuration/smtpserver") = pubEmailServer

    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = pubEmailSenderName
    .Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") = pubEmailSendAddress
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = pubEmailPassword

    .Update
    End With

    'Stop


    With iMsg
    .Configuration = iCfg
    .Subject = "Subject"
    .to = "sample@sample.com"
    .TextBody = "MessageBody"
    '.AddAttachment "FullPathToAttachment"
    .Send
    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
    Location
    Adelaide, South Australia
    Posts
    4,049
    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
    Location
    Global Village
    Posts
    185
    Hi
    if you delete the
    PHP Code:
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 
    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:
    Code:
    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")
    
    'Stop
    
    objEmail.FROM = "StrSenderAddress"
    
    objEmail.To = strTo
    
    objEmail.Subject = strSubject
    
    objEmail.TextBody = strMessage
    
    If strAttach <> "" Then objEmail.AddAttachment strAttach
    
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    
    
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.abc.com"
    
    objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    
    '_________________________________________________ ___
    '++Comment out Authentication++
    
    'objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    
    'objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = pubEmailPassword
    
    '_________________________________________________ ___
    
    objEmail.Configuration.Fields.Update
    
    objEmail.Send
    
    If Err.Number <> 0 Then
    
    MsgBox "Error in sending. " & Err.Description
    
    Else
    
    MsgBox "Sent"
    
    End If
    
    Set objEmail = Nothing
    
    End Sub
    Cheers

Posting Permissions

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