Results 1 to 3 of 3

Thread: Sending Email from Access

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    330

    Angry Sending Email from Access

    I have an access 2000 Database, I am running Windows XP pro and MS office 2003 Pro. With in my Database I want to be able to send emails off of the server and not using the local email client. I have tried several pieces of code and have searched high and low for something that works. HEre is what I have now:

    1st try:
    VB Code:
    1. Public Sub xSendEmail(ByVal sSubject As String, ByVal sRecipient As String, ByVal sSender As String, ByVal sBody As String)
    2.  
    3. 'MailMessage
    4. Set objMessage = CreateObject("CDO.Message")
    5. objMessage.Subject = sSubject
    6. objMessage.Sender = sSender
    7. objMessage.To = sRecipient
    8. objMessage.TextBody = sBody
    9.  
    10. '==This section provides the configuration information for the remote SMTP server.
    11. '==Normally you will only change the server name or IP.
    12.  
    13. objMessage.Configuration.Fields.Item _
    14. ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    15.  
    16. 'Name or IP of Remote SMTP Server
    17. objMessage.Configuration.Fields.Item _
    18. ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server name"
    19.  
    20. 'Server port (typically 25)
    21. objMessage.Configuration.Fields.Item _
    22. ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    23.  
    24. objMessage.Configuration.Fields.Update
    25.  
    26. '==End remote SMTP server configuration section==
    27.  
    28. objMessage.Send
    29.  
    30.  
    31. Set objMessage = Nothing
    32.  
    33. End Sub

    2nd try
    VB Code:
    1. Sub SendEmail(ByVal sSubject As String, ByVal sRecipient As String, ByVal sSender As String, ByVal sBody As String)
    2. SMTP_CONNECTION_TIMEOUT = 30
    3. SMTP_SERVER_PORT = 25     ' Set the port to communicate on
    4. SMTP_SERVER_NAME = "server name"
    5. CDO_USER_NAME = ""     'This can be an empty string
    6. CDO_USER_PASSWORD = ""     'This can be an empty string
    7.  
    8.    
    9.     Set objConfig = New CDO.Configuration
    10.  
    11.     ' Set the configuration fields for this message.
    12.     With objConfig.Fields
    13.         .Item(cdoSendUsingMethod) = cdoSendUsingPort
    14.         .Item(cdoSMTPServer) = SMTP_SERVER_NAME
    15.         .Item(cdoSMTPConnectionTimeout) = SMTP_CONNECTION_TIMEOUT
    16.         .Item(cdoSMTPServerPort) = SMTP_SERVER_PORT
    17.         .Item(cdoSendUserName) = CDO_USER_NAME
    18.         .Item(cdoSendPassword) = CDO_USER_PASSWORD
    19.         .Update
    20.     End With
    21.  
    22.     ' Create the new message object.
    23.     Set objMessage = New CDO.Message
    24.  
    25.     ' Set the message properties and send the message.
    26.     With objMessage
    27.         Set .Configuration = objConfig
    28.         .MimeFormatted = True
    29.         .To = sRecipient
    30.         .CC = "" 'Add CC recipients as applicable.
    31.         .BCC = "" 'Add BCC recipients as applicable.
    32.         .From = sSender  'This needs to be a valid user on SMTP_SERVER_NAME.
    33.         .Subject = sSubject
    34.     '    If Dir(strAttachment) <> "" Then
    35.     '            .AddAttachment strAttachment
    36.     '    End If
    37.         '.TextBody = strMessage 'Use this if you want to send email as plain text.
    38.         .HTMLBody = sBody
    39.         .Fields.Update
    40.         .Send
    41.     End With
    42.  
    43.     Set objMessage = Nothing
    44.     Set objConfig = Nothing
    45.  
    46. End Sub


    It appears that I am able to send from my machine but when I go to someone elses machine it no longer works.
    Swoozie
    Somedays you just should not get out of bed.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Sending Email from Access

    Any error messages?
    Check the references, might be the other machine doesn't have cdo?
    Debug your proggy, step through (if poss) and see where it is failing?
    If you are running the app and not debugging, perhaps writing to a text file as actions are made to assist in debugging?

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Washington DC
    Posts
    330

    Re: Sending Email from Access

    Error: Transport failed to connect with server.

    is the error on the .send
    Swoozie
    Somedays you just should not get out of bed.

Posting Permissions

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



Click Here to Expand Forum to Full Width