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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access & SMTP?

Status
Not open for further replies.

arniec

Programmer
Jul 22, 2003
49
US
Is there any way to program a module in Access to connect directly to an SMTP server to send e-mails (with or without attachments such as reports, queries, tables, etc)?
 
You can use CDO ("Microsoft CDO for Exchange 200? Library") to send via SMTP Something like this:

Sample Call:
Code:
Call SendEmailUsingCDO("joe@blow.net;john@doe.org", "", "", "<H4>See Attached</H4>", "me@myCo.com", "WeeklyReport", "F:\Orders.xls", "F:\Payments.xls")
Function:
Code:
Sub SendEmailUsingCDO(ByVal strTo As String, ByVal strCC As String, _
                      ByVal strBCC As String, ByVal strHTMLBody As String, _
                      ByVal strFrom As String, ByVal strSubject As String, _
                      ParamArray Attachments() As Variant)
  
  Dim email As New CDO.Message
  Dim i As Integer
  
  With email
  
    For i = 0 To UBound(Attachments)
      If dir(Attachments(i)) <> "" Then
        .AddAttachment Attachments(i)
      End If
    Next i
    
    .HTMLBody = strHTMLBody
    .From = strFrom
    .To = strTo
    .Subject = strSubject
    
    .Configuration.fields.item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 2
    
    [green]'Name or IP of Remote SMTP Server[/green]
    .Configuration.fields.item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "smtp.ev1.net"
    
    [green]'Type of authentication, NONE, Basic (Base64 encoded), NTLM[/green]
    .Configuration.fields.item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/authenticate")[/URL] = cdoBasic
    
    [green]'Your UserID on the SMTP server[/green]
    .Configuration.fields.item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusername")[/URL] = "MyUsername"
    
    [green]'Your password on the SMTP server[/green]
    .Configuration.fields.item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendpassword")[/URL] = "MyPassword"
    
    [green]'Server port (typically 25)[/green]
    .Configuration.fields.item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25
    
    [green]'Use SSL for the connection (False or True)[/green]
    .Configuration.fields.item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpusessl")[/URL] = False
    
    [green]'Connection Timeout in seconds (the maximum time
    'CDO will try to establish a connection to the SMTP server)[/green]
    .Configuration.fields.item _
    ("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")[/URL] = 60
    
    .Configuration.fields.Update
    [green]'==End remote SMTP server configuration section==[/green]
    
    .Send
  End With
End Sub

VBSlammer
redinvader3walking.gif

"You just have to know which screws to turn." - Professor Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top