Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help sending email from Access 2000 (not using Outlook)

Status
Not open for further replies.

sklambert

Programmer
Sep 15, 2003
31
US
I am trying to use SendObject to send email from Access 2000, using Netscape 7.1. I have the following code:

'****begin code****

Private Sub SENDEMAIL_Click()

Dim ORIGIN, DESTINATION, SENDTO, SUBJECT, MESSAGE As String

ORIGIN = "ebay2628@yahoo.com"
DESTINATION = [EMAIL ADDRESS]
SENDTO = [EMAIL ADDRESS]
SUBJECT = "Your item has been shipped."
MESSAGE = "We have shipped your item. The tracking number is " & [TRACKING NUMBER] & "."

DoCmd.SendObject acSendForm, , acFormatTXT, SENDTO, , , SUBJECT, MESSAGE, True

End Sub

'*****end code********

What happens is I get a window to send a new message in Netscape, and the SUBJECT and body (MESSAGE) are populated correctly, but not the send to email address (SENDTO). The From field in the email is defaulting to the settings in Netscape, which I can live with. I was hoping to use the "ebay2628" email address, so the user could reply to that address, no matter which email account I use, but if that cant be done, it wouldn't be an issue. Any help would be appreciated. I posted this question in another forum with no success.
 
Try using Simple Mail Transfer Protocol (SMTP). Here's a routine I wrote. See if it does what you want. (Note that you will have to enable SMTP on your sever)
Code:
Function SMTP(strNTUserName As String, _
              strNTUserPwd As String, _
              strFrom As String, _
              strTo As String, _
     Optional strSubject As String, _
     Optional strBody As String, _
     Optional strBCC As String, _
     Optional strCC As String, _
     Optional strAttachment As String, _
     Optional strHTMLBody As String, _
     Optional strMailServer As String = "nameOfYourDefaultMailServer")

'********************************
'*  Declaration Specifications  *
'********************************

    Dim email As New CDO.Message
    
    On Error GoTo ErrHandler

    With email
        
        .From = strFrom                         'Example: "LastName.FirstName@whatever.com"
        .To = strTo                           'Example: "LastName.FirstName@Whatever.com"
        
        If (Len(strAttachment) > 0) Then .AddAttachment strAttachment
        If (Len(strHTMLBody) > 0) Then .HTMLBody = strHTMLBody                '&quot;<H4>See attached file</H4>&quot;
        If (Len(strBCC) > 0) Then .BCC = strBCC
        If (Len(strCC) > 0) Then .CC = strCC
        If (Len(strSubject) > 0) Then .Subject = strSubject
        If (Len(strBody) > 0) Then .TextBody = strBody
        
        .Configuration.Fields.Item(&quot;[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing&quot;)[/URL] = 2
        .Configuration.Fields.Item(&quot;[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver&quot;)[/URL] = strMailServer    'Name or IP of Remote SMTP Server
        .Configuration.Fields.Item(&quot;[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/authenticate&quot;)[/URL] = 0              'Type of authentication, NONE, Basic (Base64 encoded), NTLM
        .Configuration.Fields.Item(&quot;[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusername&quot;)[/URL] = strNTUserName  'Your UserID on the SMTP server
        .Configuration.Fields.Item(&quot;[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendpassword&quot;)[/URL] = strNTUserPwd   'Your password on the SMTP server
        .Configuration.Fields.Item(&quot;[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport&quot;)[/URL] = 25           'Server port (typically 25)
        .Configuration.Fields.Item(&quot;[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpusessl&quot;)[/URL] = False         'Use SSL for the connection (False or True)
        .Configuration.Fields.Item(&quot;[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout&quot;)[/URL] = 60 'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
        .Configuration.Fields.Update
    
        .Send
  
  End With

'********************
'*  Exit Procedure  *
'********************
        
ExitProcedure:

    Exit Function

'****************************
'*  Error Recovery Section  *
'****************************
        
ErrHandler:
        
    Err.Raise Err.number, &quot;SMTP&quot;, &quot;An the following error occurred while attempting to send mail via SMTP.&quot; & vbCrLf & Err.Description
        
    Resume ExitProcedure

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top