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

using VB to send an email

Status
Not open for further replies.

itechC

Programmer
Feb 13, 2003
71
0
0
CA
I would like to email the content on a form using windows default email (outlook). Any ideas?
 
I have used this dll and found it very good.

SMTP sender tool written by Igor Ostrovsky (OstroSoft). See
Here is some code to get you started.
Please note I have created and set many variables here, you can just replaced these with strings.

Code:
'declare the smtp email object
Public WithEvents oSMTP As OSSMTP.SMTPSession
Public strSendFileName As String
Public strCompressedFileName As String

' on form load
    'prepare email object for use
    Set oSMTP = New OSSMTP.SMTPSession

Private Sub SendEmail()
    Dim sError As String
    
    'handle errors
    On Error GoTo SendEmailErr
    
    With oSMTP
        'for now, assume no authentication on SMTP machine
        .AuthenticationType = 0
        
        'use the simplified syntax to just add a fully specified path name for attachment
        .Attachments.Add strWorkingDirectory & "\" & strCompressedFileName

        'prepare standard email content (eg. server, from, to, subject etc.)
        .Server = strEmailServer
        .MailFrom = strEmailFrom
        .SendTo = strEmailTo
        .MessageSubject = strEmailSubject
        .MessageHTML = strEmailMessageBody
        'NB: need to set a return reciept here  -how
    
        'send the message
        .SendEmail
    End With
    Exit Sub

SendEmailErr:
    sError = "Received an error trying to send email: " & _
             "      Error Number:   " & Trim(Str(Err.Number)) & vbCrLf & _
             "      Description:      " & Err.Description
    Call PutMsg(sError)
    Call MsgBox(sError, vbCritical, "Unable to send email")
    Unload Me
End Sub


Rob Hasard
(VB6 /SQL 7.0 /CR8.5)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top