FREE tutorial,solution,RSS Feeds on Operating Systems, Programming, Web Development, Applications, Databases, Networking, Hardware, Security, SEO Free Expertsforge Membership
Join us as Moderator
Submit Article to Expertsforge.com Submit Article My Expertsforge
 
RSS Feeds, Help Help RSS Feeds
bannertop
 

Lotus Notes/Domino Tutorial: Send Lotus Notes Email with attachment using Domino objects in VB

jawahar
9/18/2007 9:29:32 AM, Views: 952
The following tutorial and code can be used to send lotus notes mail/memo using DOM in VB(Visual Basic)

This method eliminates the password prompt that will show when the notes is locked and the script is executed

Public recep, ccRecipient, passwd, savemsg, attachment1

Private Sub Form_Load()
Me.Hide
ReDim ccRecipient(4)
ReDim recep(6)

passwd="yourpasswordhere"
savemsg="yes" ' If you want the mail to be stored in your sent items, otherwise "no"

recep(0) = "rec1/company"
recep(1) = "rec2/company"

ccRecipient(0) = "rec3/company"
ccRecipient(1) = "rec4/company"
toname = "All"
attachment1 = "C:\someattachment.xls"
Call sendNotesMail(toname)

Unload Me
End Sub


Function sendNotesMail(toname)
      Dim domNotesDocumentMemo As Domino.NotesDocument
      Dim domSession As New Domino.NotesSession
      Dim domNotesDBDir As Domino.NotesDbDirectory
      Dim domNotesDatabaseMailFile As Domino.NotesDatabase
      Dim DomNotesItem As Domino.NotesItem
      Dim sUser As String
      Dim objNotesRichTextItem As Domino.NotesRichTextItem

      
      domSession.Initialize (passwd)
      sUser = domSession.UserName
      Set domNotesDBDir = domSession.GetDbDirectory(sUser)
      
      Set domNotesDatabaseMailFile = domNotesDBDir.OpenMailDatabase
      
      ' Create a new memo document.
      Set domNotesDocumentMemo = domNotesDatabaseMailFile.CreateDocument
      Call domNotesDocumentMemo.AppendItemValue("Form", "Memo")
      Call domNotesDocumentMemo.AppendItemValue("From", domSession.CommonUserName)
      
      
      subj = "Lotus Notes Email using DOM and VB - an example"
      input1 = "Hi " & toname & ","
      input2 = "Lotus notes email using vb"
      input3 = "Regards,"
      input4 = "Your name"
      mailbody = input1 & Chr(13) & input2 & Chr(13) & Chr(13) & input3 & Chr(13) & input4 & Chr(13) & Chr(13)
      
      Call domNotesDocumentMemo.AppendItemValue("SendTo", "")
      'Now get a handle on the item
      Set DomNotesItem = domNotesDocumentMemo.GetFirstItem("SendTo")
      'Now pass your array
      For Each r In recep
       If r <> "" Then
          Call DomNotesItem.AppendToTextList(r)
       End If
      Next
      
            'create or instantiate the item
            Call domNotesDocumentMemo.AppendItemValue("CopyTo", "")
            'Now get a handle on the item
            Set DomNotesItem = domNotesDocumentMemo.GetFirstItem("CopyTo")
            'Now pass your array
            For Each s In ccRecipient
             If s <> "" Then
                Call DomNotesItem.AppendToTextList(s)
             End If
            Next

      Call domNotesDocumentMemo.AppendItemValue("Subject", subj)
      Set objNotesRichTextItem = domNotesDocumentMemo.CreateRichTextItem("Body")
      Call objNotesRichTextItem.AppendText(mailbody)
    ' Call domNotesDocumentMemo.AppendItemValue("Body", mailbody)
      If attachment1 <> "" Then
            Call objNotesRichTextItem.EmbedObject(1454, "", attachment1, "Attachment")
      End If
      If Trim(LCase(savemsg)) = "yes" Then
            domNotesDocumentMemo.SaveMessageOnSend = True
      Else
            domNotesDocumentMemo.SaveMessageOnSend = False
      End If

      domNotesDocumentMemo.Send (False)
      
      Set domNotesDocumentMemo = Nothing
      Set domNotesDatabaseMailFile = Nothing
      Set domNotesDBDir = Nothing
      Set domSession = Nothing
      Set AttachME = Nothing
      Exit Function
ErrorHandler:
      MsgBox Err.Number & " " & Err.Description
End Function
Next Steps:
Add this Tutorial to:
Blink Blink del.icio.ous Del.icio.us Digg Digg
Fark Fark Furl Furl Google Google
Reddit Reddit Simpy Simpy Spurl Spurl
Technorati Technorati Windows Live Win Live Yahoo Yahoo
Rate Me!
Avg Visitor Rating: Average Visitor Rating is 3 out of 5
Number of Ratings : 3 Votes
Rate:
Send Private MessageSend Message
Signup / Login To View the Solution or Provide Comments
Post Comment/Solution
Comment:*
        (Link Rules) 
  Use : [bold] for <b>; [/bold] for </b>; [italic] for <i>; [/italic] for </i>; [code] & [/code] for code
 
Categories
Options
Lotus Notes/Domino RSS Feed
Most Popular Tutorial
Most Popular Solution
No Records!
Top Rated
Top Rankers
Overall
1. jawahar (250)
Yearly -2008
No Rankings!
Expertsforge Sponsors
bnrtop