Sign in to follow this  
Followers 0

Send E-Mail via Lotus Notes

12 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#2 ·  Posted

Thanx Great script.

Share this post


Link to post
Share on other sites

#3 ·  Posted

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¤

Share this post


Link to post
Share on other sites

#4 ·  Posted

very nice raquien!!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hello,

thank you for this wonderful script ! One question: how to put EndLineCharacters in "body of the email" ?

So my email would look like this:

first line
second line
Edited by ALIENQuake

Share this post


Link to post
Share on other sites

#7 ·  Posted

$var = "first line" & @CRLF & "second line"


I felt in love with AutoItObject [and the new Map type!].

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

$var = "first line" & @CRLF & "second line"

But this script creating lono.exe application with must be run from CMD/Powershell - i cannot use autoscript syntax there.

CMD:

lono.exe somebody@xxx.xxx "Subject" "Message" "" "" true
Edited by ALIENQuake

Share this post


Link to post
Share on other sites

#9 ·  Posted

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!

1 person likes this

Share this post


Link to post
Share on other sites

#10 ·  Posted

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!

Share this post


Link to post
Share on other sites

#11 ·  Posted

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:

UDFs:
Active Directory (2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (NEW 2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

Share this post


Link to post
Share on other sites

#12 ·  Posted

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0