Views

Histats

Vitrine

VBA Tips - SendLotusEmails - Envie e-mail com o Lotus Notes

Envie e-mails através do Lotus Notes. Requer as Classes de Automação do Lotus (Lotus Automation Classes - notes32.tlb).

   ' Attribute VB_Name = "modLotus"    ' This public sub will send a mail and attachment if neccessary to the recipient including the body text.  ' Requires that notes client is installed on the system.    Public Sub SendLotusEMail(Subject As String, Attachment As String, recipient As String, bodytext As String, saveit As Boolean)        ' Set up the objects required for Automation into lotus notes            Dim MailDB As Object ' The mail database            Dim UserName As String ' The current users notes name            Dim MailDBName As String ' THe current users notes mail database name            Dim MailDoc As Object ' The mail document itself            Dim AttachME As Object ' The attachment richtextfile object            Dim LotusSession As Object ' The notes session            Dim EmbedObj As Object ' The embedded object (Attachment)            ' Start a session to notes            Set LotusSession = CreateObject("Notes.NotesSession")            ' Get the sessions username and then calculate the mail file name            ' You may or may not need this as for MailDBname with some systems you            ' can pass an empty string            UserName = LotusSession.UserName            MailDBName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"            ' Open the mail database in notes            Set MailDB = LotusSession.GetDatabase("", MailDBName)              If MailDB.isOpen = True Then                        ' Already open for mail              Else                      MailDB.OPENMAIL              End If            ' Set up the new mail document            Set MailDoc = MailDB.CreateDocument            MailDoc.Form = "Memo"            MailDoc.sendto = recipient            MailDoc.Subject = Subject            MailDoc.body = bodytext            MailDoc.SaveMessageOnSend = saveit            ' Set up the embedded object and attachment and attach it            If Attachment <> "" Then                    Set AttachME = MailDoc.CreateRichTextItem("Attachment")                    Set EmbedObj = AttachME.EmbedObject(1454, "", Attachment, "Attachment")                    MailDoc.CreateRichTextItem ("Attachment")            End If            ' Send the document            MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder            MailDoc.Send 0, recipient                  ' Clean Up            Set MailDB = Nothing            Set MailDoc = Nothing            Set AttachME = Nothing            Set LotusSession = Nothing            Set EmbedObj = Nothing    End Sub

Deixe os seus comentários! Envie este artigo, divulgue este link na sua rede social...


Tags: VBA, Lotus, Lotus Notes, e-mails, notes32.tlb, send,



LinkWithinBrazilVBAExcelSpecialist

Related Posts Plugin for WordPress, Blogger...