VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Updated email using Lotus Notes with attachment, and fixed bug with older versions of Outlook where

by David Koopman (11 Submissions)
Category: Internet/HTML
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 15th January 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Updated email using Lotus Notes with attachment, and fixed bug with older versions of Outlook where the Body was not showing up.

Rate Updated email using Lotus Notes with attachment, and fixed bug with older versions of Outlook where



To check for pass fail I am returning a Long. Either a 1 for pass or a 0 for failure so the End User knows whether the Send was successful or not. Could also return Boolean(True/False). Below is the front end code to describe how I referenced the function and passed the parameters. Enjoy

Create a Project Named Mail
Add a Class Module Named CMail and paste function below.
Add a form with a Command button and 6 text boxes and paste the code on the bottom.

Public Function SendMail(ByVal strTo As String, _
                          ByVal strFrom As String, _
                          ByVal strCC As String, _
                          ByVal strSubject As String, _
                          ByVal strBody As String, _
                          ByVal strAtt As String) As Long
                                                            
  'Basic Error Handling
On Error GoTo EmailError
    Dim Maildb As Object 'The mail database
    Dim MailDoc As Object 'The mail document itself
    Dim Session As Object 'The notes session
    Dim oAttachment As Object
            
    'Start a session to notes
    Set Session = CreateObject("Notes.NotesSession")
    Set Maildb = Session.GETDATABASE("", "") 'set database to default mail database

    If Maildb.OPENMAIL = False Then
      'Set up the new mail document
       Set MailDoc = Maildb.CREATEDOCUMENT 'Create Document
       Set oAttachment = MailDoc.CREATERICHTEXTITEM("BODY")
           MailDoc.Form = "Memo"
           MailDoc.SendTo = strTo
           MailDoc.From = strFrom
           MailDoc.CopyTo = strCC
           MailDoc.Subject = strSubject
                
           Call oAttachment.APPENDTEXT(strBody)
           If strAtt <> "" Then 'Attach File.
            Call oAttachment.EMBEDOBJECT(1454, "", strAtt) 
           End If
           MailDoc.SAVEMESSAGEONSEND = True 'Save copy to Sent Folder
           'Send the document
           MailDoc.PostedDate = Now()
           MailDoc.SEND (False)
           'Succesfully sent
           SendMail = 1
           'Clean Up
           Set Maildb = Nothing
           Set MailDoc = Nothing
           Set Session = Nothing
           Set oAttachment = Nothing

     Else
           'Lotus Notes not open
           SendMail = 0
           Exit Function
     End If
             
EmailExit:
      Exit Function
  
EmailError:
    'Send Failed
    SendMail = 0
    Debug.Print Err.Number & Err.Description
            App.StartLogging App.Path & "\CMAC_Email.log", vbLogToFile
            App.LogEvent Now & Err.Description, vbLogEventTypeError
      Resume EmailExit

End Function



'=============================================================================
'=============================================================================

'On Form

Private Sub cmdSend_Click

Dim oEmail as New Mail.CMail
Dim lngReturn as Long

lngReturn = oEmail.SendMail(text1.Text, _
                          text2.Text, _
                          text3.Text, _
                          text4.Text, _
                          text5.Text, _
                          text6.Text)
                      
If lngReturn = 1 Then   'Email successful
    MsgBox "Email sent to recipient!" & vbCrLf & _
    "Check Lotus for successful delivery!", vbOKOnly+vbSystemModal, _
    "Updated and Completed"
   Exit Sub
Else 'Email failed
   MsgBox "Failed" & vbCrLf & Err.Description, vbOKOnly, "Failure occurred!"
   Exit Sub
End If

End Sub

Download this snippet    Add to My Saved Code

Updated email using Lotus Notes with attachment, and fixed bug with older versions of Outlook where Comments

No comments have been posted about Updated email using Lotus Notes with attachment, and fixed bug with older versions of Outlook where. Why not be the first to post a comment about Updated email using Lotus Notes with attachment, and fixed bug with older versions of Outlook where.

Post your comment

Subject:
Message:
0/1000 characters