Jump to content

Send E-Mail via Lotus Notes


raquien
 Share

Recommended Posts

This is the script that I am using when sending Lotus Notes email from command line. The original code was in VB from

http://vbcity.com/forums/topic.asp?tid=19730&page=2

Converted with the help of "vaconvert.au3" found here and modified a little.

Usage:

lono.exe toyou@address.com "test subject" "body of the email" "d:\sample\attachment\lono.au3" true

true means to save a copy in the sent mail or false otherwise.

#cs
Created with AutoIt version 3.2.6.0 / Beta 3.2.7.3
Created by: Raquien Rabuya
Date: September 20, 2007
This is a command line utility. You can send email using the following format

lono.exe <recipient email> <'subject'> <'body of the email'> <'attachment full path'> <save (true/false)>"

or you can integrate it to your own script by using the function SendNotesMail()
#ce

#include <date.au3>

CheckParam()
SendNotesMail($CmdLine[1], $CmdLine[2], $CmdLine[3], $CmdLine[4], $CmdLine[5])

Func SendNotesMail($recipient, $Subject, $bodytext, $attachment, $saveit)
       ;Start a $Session to notes
        $Session = ObjCreate("Notes.NotesSession")
       ;Get the sessions $UserName and then calculate the mail file name
        $UserName = $Session.UserName
        $MailDbName = StringLeft($UserName, 1) & StringRight($UserName, (StringLen($UserName) - StringInstr(1, $UserName, " "))) & ".nsf"
       ;Open the mail database in notes
        $Maildb = $Session.GETDATABASE("", $MailDbName)
        If $Maildb.IsOpen = 1 Then
           ;Already open for mail
        Else
            $Maildb.OPENMAIL()
        EndIf
       ;Set up the new mail document
        $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
            If FileExists(@ScriptDir & "\" & $attachment) Then
                $filename = $attachment
                $fullpath = @ScriptDir & "\" & $attachment
            ElseIf FileExists($attachment) Then
                $pos = StringInStr($attachment,"\",0,-1)
                $filename = StringTrimLeft($attachment,$pos)
                $fullpath = $attachment
            Else
                MsgBox(0,"LoNo Error","attachment not found")
                Exit
            EndIf
            $AttachME = $MailDoc.CREATERICHTEXTITEM($filename)
            $EmbedObj = $AttachME.EMBEDOBJECT(1454, "", $fullpath, $filename)
        ;$MailDoc.CREATERICHTEXTITEM($filename)
        EndIf
       ;Send the document
        $MailDoc.PostedDate = _Now();Gets the mail to appear in the sent items folder
        $MailDoc.SEND(0, $recipient)
        $Maildb = "NULL"
        $MailDoc = "NULL"
        $AttachME = "NULL"
        $Session = "NULL"
        $EmbedObj = "NULL"
EndFunc

Func CheckParam()
    If $CmdLine[0] <> 5 Then
        MsgBox(0,"LoNo Error","Check Paramates. Format is: lono <recipient email> <'subject'> <'body of the email'> <'attachment full path'> <save (true/false)>")
        Exit
    ElseIf Not StringRegExp($CmdLine[1],"(.*?)@(.*?).com",0) Then
        MsgBox(0,"LoNo Error","Not a valid email address")
        Exit
    EndIf
EndFunc
Link to comment
Share on other sites

  • 2 weeks later...

to send mail from lono try simply using :

#include <INet.au3>
_INetMail ( $s_MailTo, $s_MailSubject, $s_MailBody )oÝ÷ Økçbµ©ÝÜ(®Gë-~)Þ~æz'ç¢×ºÇ¢·lÝk)¨®x§©Ý!Ê.ÖÞ+-jH§Ø^±ëp¡«­¢+Ø¥¹±Õ±Ðí%9йÔÌÐì)}%9ÑMµÑÁ5¥° ÀÌØíÍ}MµÑÁMÉÙÈ°ÀÌØíÍ}ɽµ9µ°ÀÌØíÍ}ɽµÉÍÌ°ÀÌØíÍ}Q½ÉÍÌl°ÀÌØíÍ}MÕ©Ðl°ÀÌØíÍ} ½äl°ÀÌØíÍ}¡±¼°l°ÀÌØíÍ}¥ÉÍÐl°ÀÌØí}ÑÉuuuut¤
Link to comment
Share on other sites

  • 3 years later...
  • 2 years later...

it took me three days to finally get to trying this code and it works great. I will start implementing it to my other scripts today.

For the benefit of all other newbies (like myself) using Lotus Notes as their default email client, here's the bare minimum script I have used and it worked for me:

#include <date.au3>

Global $recipient, $Subject, $bodytext, $attachment, $saveit
$recipient = "youremail@gmail.com"
$Subject = "test"
$bodytext = "more test"
$attachment = "C:Documents and Settingsyour.nameMy Documentsscriptsemail test.au3"
$saveit = True
SendNotesMail($recipient, $Subject, $bodytext, $attachment, $saveit)

Func SendNotesMail($recipient, $Subject, $bodytext, $attachment, $saveit)
;Start a $Session to notes
$Session = ObjCreate("Notes.NotesSession")
;Get the sessions $UserName and then calculate the mail file name
$UserName = $Session.UserName
$MailDbName = StringLeft($UserName, 1) & StringRight($UserName, (StringLen($UserName) - StringInStr(1, $UserName, " "))) & ".nsf"
;Open the mail database in notes
$Maildb = $Session.GETDATABASE("", $MailDbName)
If $Maildb.IsOpen = 1 Then
;Already open for mail
Else
$Maildb.OPENMAIL()
EndIf
;Set up the new mail document
$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
If FileExists(@ScriptDir & "" & $attachment) Then
$filename = $attachment
$fullpath = @ScriptDir & "" & $attachment
ElseIf FileExists($attachment) Then
$pos = StringInStr($attachment, "", 0, -1)
$filename = StringTrimLeft($attachment, $pos)
$fullpath = $attachment
Else
MsgBox(0, "LoNo Error", "attachment not found")
Exit
EndIf
$AttachME = $MailDoc.CREATERICHTEXTITEM($filename)
$EmbedObj = $AttachME.EMBEDOBJECT(1454, "", $fullpath, $filename)
;$MailDoc.CREATERICHTEXTITEM($filename)
EndIf
;Send the document
$MailDoc.PostedDate = _Now();Gets the mail to appear in the sent items folder
$MailDoc.SEND(0, $recipient)
$Maildb = "NULL"
$MailDoc = "NULL"
$AttachME = "NULL"
$Session = "NULL"
$EmbedObj = "NULL"
EndFunc ;==>SendNotesMail

To use it: change values of variables defined at the beginning

press F5 and enjoy :)

Again, many thanks to Raquien!

Edited by DanielTyrkiel
Link to comment
Share on other sites

  • 2 months later...
  • 1 month later...

it took me three days to finally get to trying this code and it works great. I will start implementing it to my other scripts today.

For the benefit of all other newbies (like myself) using Lotus Notes as their default email client, here's the bare minimum script I have used and it worked for me:

#include <date.au3>

Global $recipient, $Subject, $bodytext, $attachment, $saveit
$recipient = "youremail@gmail.com"
$Subject = "test"
$bodytext = "more test"
$attachment = "C:Documents and Settingsyour.nameMy Documentsscriptsemail test.au3"
$saveit = True
SendNotesMail($recipient, $Subject, $bodytext, $attachment, $saveit)

Func SendNotesMail($recipient, $Subject, $bodytext, $attachment, $saveit)
;Start a $Session to notes
$Session = ObjCreate("Notes.NotesSession")
;Get the sessions $UserName and then calculate the mail file name
$UserName = $Session.UserName
$MailDbName = StringLeft($UserName, 1) & StringRight($UserName, (StringLen($UserName) - StringInStr(1, $UserName, " "))) & ".nsf"
;Open the mail database in notes
$Maildb = $Session.GETDATABASE("", $MailDbName)
If $Maildb.IsOpen = 1 Then
;Already open for mail
Else
$Maildb.OPENMAIL()
EndIf
;Set up the new mail document
$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
If FileExists(@ScriptDir & "" & $attachment) Then
$filename = $attachment
$fullpath = @ScriptDir & "" & $attachment
ElseIf FileExists($attachment) Then
$pos = StringInStr($attachment, "", 0, -1)
$filename = StringTrimLeft($attachment, $pos)
$fullpath = $attachment
Else
MsgBox(0, "LoNo Error", "attachment not found")
Exit
EndIf
$AttachME = $MailDoc.CREATERICHTEXTITEM($filename)
$EmbedObj = $AttachME.EMBEDOBJECT(1454, "", $fullpath, $filename)
;$MailDoc.CREATERICHTEXTITEM($filename)
EndIf
;Send the document
$MailDoc.PostedDate = _Now();Gets the mail to appear in the sent items folder
$MailDoc.SEND(0, $recipient)
$Maildb = "NULL"
$MailDoc = "NULL"
$AttachME = "NULL"
$Session = "NULL"
$EmbedObj = "NULL"
EndFunc ;==>SendNotesMail

To use it: change values of variables defined at the beginning

press F5 and enjoy :)

Again, many thanks to Raquien!

Thanks for posting this!

Do you know how to change it so that it will embed the document/picture with a preview on the email?

I imagine it would be between these two lines:

$AttachME = $MailDoc.CREATERICHTEXTITEM($filename)
$EmbedObj = $AttachME.EMBEDOBJECT(1454, "", $fullpath, $filename)

Also how can I send two attachments?

Thanks!

Link to comment
Share on other sites

  • 5 months later...

Thanks for posting this!

Do you know how to change it so that it will embed the document/picture with a preview on the email?

I imagine it would be between these two lines:

 

$AttachME = $MailDoc.CREATERICHTEXTITEM($filename)
$EmbedObj = $AttachME.EMBEDOBJECT(1454, "", $fullpath, $filename)

Also how can I send two attachments?

Thanks!

 

This script is works great to send right away ... I would like to create an mail msg without actually sending it right away so i can edit the Body text, Any ideas???

Thanks!

Link to comment
Share on other sites

I think you simply need to remove this part:

;Send the document
$MailDoc.PostedDate = _Now();Gets the mail to appear in the sent items folder
$MailDoc.SEND(0, $recipient)
$Maildb = "NULL"
$MailDoc = "NULL"
$AttachME = "NULL"
$Session = "NULL"
$EmbedObj = "NULL"

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I tired above and nothing happens at all

i found this script in VB -->

Hi,

The code down below helps me attach documents to lotus mails. Also, it does not send the newly created mail immediately, it shows up in the Notes window as a new memo.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Maildb As Object 'The mail database
        Dim MailDoc As Object 'The mail document itself
        Dim AttachME As Object 'The attachment richtextfile object
        Dim Session As Object 'The notes session
        Dim EmbedObj As Object 'The embedded object (Attachment)
        Dim uiWorkspace As Object 'The Notes Workspace
        Dim uiDoc As Object 'The UI document
        Dim strServer As String 'Server Name
        Dim strFileName As String 'File Name
        Dim strFile As String 'File to be attached to the mail

        Try
            'Start a session to notes
            Session = CreateObject("Notes.NotesSession")
            'Create a Workspace
            uiWorkspace = CreateObject("Notes.NotesUIWorkspace")

            Maildb = Session.GetDatabase("", "")
            Maildb.OpenMail()
            strServer = Maildb.Server
            strFileName = Maildb.FilePath

            If Maildb.IsOpen = False Then
                Maildb.OPENMAIL()
            End If

            'Set up the new mail document
            MailDoc = Maildb.CREATEDOCUMENT
            With MailDoc
                .Form = "Memo"
                .sendto = "abc@xyz.com"
                .Subject = "Test Subject"
                .Body = "Test Body"
                '.SAVEMESSAGEONSEND = saveit
            End With

            'Set up the embedded object and attachment and attach it
            strFile = "c:\error.doc"
            If strFile <> "" Then
                AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
                EmbedObj = AttachME.EMBEDOBJECT(1454, "", strFile, "Attachment")
            End If

            'Create and Open a NotesUIDocument Instance
            uiDoc = uiWorkspace.EditDocument(True, MailDoc)

        Catch caught As Exception
            MessageBox.Show(caught.Message)
        Finally
            'Clean(Up)
            Maildb = Nothing
            MailDoc = Nothing
            AttachME = Nothing
            Session = Nothing
            EmbedObj = Nothing
        End Try
    End Sub

:thumb:
Suraj
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...