Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2005

    Unanswered: SendMail and Lotus Notes

    I have always used the Macro SendObject, form, HTML format, then set the to, subject and message in the macro.

    I understand there is ways to do this using code so you don't have to go to the Notes client and click send with each email. However I am not quite understanding what needs to be done. I have found code such as below on some sites that say it will work, like -

    Option Explicit

    Private Sub SendEmailLotus()
    Dim s As Object
    Dim db As Object
    Dim doc As Object
    Dim sMsg As String

    Set s = CreateObject("Notes.Notessession") 'Create notes session
    Set db = s.getdatabase("", "") 'Set db to database not yet named
    Call db.openmail 'Set database to default mail database
    Set doc = db.createdocument 'Notesdocument '.New '(db) ' create a mail document
    sMsg = "Mail has been sent: " & Date & " " & Time() & Chr$(10) & _
    "This is a test of an email message from VB." & vbCrLf & Text1.Text '
    Call doc.replaceitemvalue("SendTo", "Eric Burdo") '
    Call doc.replaceitemvalue("Subject", "VB message") '
    Call doc.replaceitemvalue("Body", sMsg) '
    Call doc.Send(False) 'Send the message
    MsgBox doc.getitemvalue("Body")(0) '
    Set s = Nothing 'Close connection to free memory
    Set db = Nothing 'Cleanup
    Set doc = Nothing 'Cleanup
    End Sub

    However I am not quite sure how to set this up to email the information off of a form that opens in an email, and what variables I need to change in this code to make it work for my situation. The form has about 5 or 6 fields that need to be shown on the email (always liked the HTML format) when it opens. I can trigger the open when needed (when the condition to send the information via email is met).

    Any help on this from someone who has past experience in making this work? I would like to have this just send behind the scenes.

    Thanks for everyone's help both now and in the past!

  2. #2
    Join Date
    Dec 2004
    Madison, WI
    As far as using fields on a form, there are some email examples in the code bank but they use the sendobject command for outlook.

    As far as the code to create or send the email for lotus, you'd probably need to google for code to do that. I googled for Groupwise code to use in vba and it worked great.

    (or hope someone else has the code and posts it here as a response.)
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    Jul 2004
    South Dakota
    I have some code at the office to send email using CDO. I can post it tomorrow. Think it will have what you are looking for.


  4. #4
    Join Date
    Jul 2004
    South Dakota
    Here is the code that I use to send emails without using Outlook or another email client.

    Public Function SendEmail(pFrom As String, pTo As String, pSubj As String, _
        Optional pBody As String, Optional pAttach As String) As Boolean
        On Error GoTo ErrHandler
        Dim objMessage As Object
        Set objMessage = CreateObject("CDO.Message")
        objMessage.From = pFrom
        objMessage.To = pTo
        objMessage.Subject = pSubj
        objMessage.HTMLBody = pBody
        If pAttach <> "" Then objMessage.AddAttachment pAttach
        objMessage.Configuration.Fields.Item _
        ("") = 2
        'Name or IP of Remote SMTP Server
        objMessage.Configuration.Fields.Item _
        ("") = EnterYourServerHere
        'Server port (typically 25)
        objMessage.Configuration.Fields.Item _
        ("") = 25
        'if made it here then email was sent
        SendEmail = True
        Set objMessage = Nothing
        Exit Function
        SendEmail = False
        Resume ExitHere
    End Function
    I just create an HTML formatted string for the body and pass that to the function. It does use Microsoft CDO.

    Hope it helps.


Posting Permissions

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