• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 789
  • Last Modified:

Email Missing Signature

I need the code below to add a signature.  I already have one stored in lotus notes, i'd like to use that one.   Also,  I need to attach a file and am not sure how to do that.   Lets say the path is the C Drive


Private Sub Command37_Click()
Dim rs As New ADODB.Recordset
 Dim strEmail As String
 
 Set Lotus2 = CreateObject("Notes.NotesSession")
 Set mailbox = Lotus2.GetDatabase("", "")
 mailbox.OPENMAIL
 Set msg = mailbox.CreateDocument
 msg.ReplaceItemValue "Form", "Memo"
 Set msgNoteText = msg.CreateRichTextItem("Body")
 
 
 If Format(Date - 1, "dddd") = "Sunday" Then
 
 msg.ReplaceItemValue "Subject", "AM Consolidated DSR" & " " & Date - 3
 
  msgNoteText.AppendText "Attached is the AM Consolidated DSR" & " " & Date - 3

 
 Else
 
 msg.ReplaceItemValue "Subject", "AM Consolidated DSR" & " " & Date - 1
 
  msgNoteText.AppendText "Attached is the AM Consolidated DSR" & " " & Date - 1
msg.ReplaceItemValue "Signature", "Signature"
 End If
 

 Set SendTo = msg.ReplaceItemValue("SendTo", "")
 
 rs.Open "tblAttendeeList", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
 
 Do While Not rs.EOF
   If Not IsNull(rs!Email) Then
     strEmail = rs!Email
     SendTo.AppendToTextList strEmail
   End If
   rs.MoveNext
 Loop
 
 rs.Close
 Set rs = Nothing
 
 msg.Save True, True
 CreateObject("Notes.NotesUiWorkspace").EDITDOCUMENT True, msg
 
End Sub


Thank you.

0
komskex
Asked:
komskex
1 Solution
 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
I don't work with Lotus Notes, but in Outlook a Signature file is added by Outlook, and cannot be added through automation. That said, you can add the sig to the Body of the email, if desired.

I have no idea how to do an attachment in Lotus, sorry.

0
 
SysExpertCommented:
In Lotus Notes, did you define an internal signature, or are you using an external file ?

If internal, you will need to find the docs ( probably a profile doc 0 and grab the text of the signature.

IN THIS CASE IT MAY BE easier to simply point it to an external file.

The signature only works by default, when you are using the UI classes, not the backend ones.



I hope this helps !
0
 
komskexAuthor Commented:
I'm not really sure what a UI class is ? I do have a signature stored in lotus notes.  Can you tell me more about UI Class ? Is it an easy fix for my code above ?
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
qwaleteeCommented:
The short answer: see http://www.experts-exchange.com/Q_21069618.html#a11638305
The author is reputed to be reputable :)

The long answer:

There are about 25 lines of code in the Notes mail template that add the signature. You coudl copy those (template LotusScript is almost idnetical to VB).

Or, you could reinvent.

Either way, you could run into one problem. See, there are three ways a signature can be specified:
1) plain text, value is stored in mailbox/calendar profile
2) external HTML file, reference to filename is stored in mailbox/calendar profile
3) graphic (external GIF file), reference to filename is stored in mailbox/calendar profile

For #1, recreating the code is pretty trivial.

For #2/#3, it doesn;t use the Notes data API. It uses the client API, which actually controls the lcient very similarly to the menu structure. For #2/#3, it essetially invokes the code behind File>Import,HTML or File->Import,GIF. So you'll have todo the same.

Now that you understand all that, you can go back to the short answer and see what it does, then adapt it to VB. Just realize that all those Me. stuff are refering to a home-grown object, but that objects properties are really all just references to the mailbox, the mailbox/calendar profile, and the current (new) message
0
 
qwaleteeCommented:
Or, we could turn your code inside out. Instead of
- creating the "draft" message record with data
- and loading into the UI,

we can do it the other way around
- load a new empty memo in the UI
- manipulate the undelrying message record to populate the data

Advantage? New memos in the UI automatically load their signature, so that part is taken care of before we get to manipulating our own data.
0
 
komskexAuthor Commented:
Sorry i'm going to have to be spoon fed here, because nothing above is anything i understand.   I'll research UI when i get the chance.   Thank you.
0
 
qwaleteeCommented:
How about this

Private Sub Command37_Click()
 
Dim rs As New ADODB.Recordset
 Dim strEmail As String
 
 Set Lotus2 = CreateObject("Notes.NotesSession")
 Set mailbox = Lotus2.GetDatabase("", "")
 mailbox.OPENMAIL
 
Set NotesUI = CreateObject("Notes.NotesUiWorkspace")
Set newMessage = NotesUI.ComposeDocument(mailbox.server,mailbox.filepath,"Memo")
newMessage.Save
 Set msg = newMessage.Document 'get access to the record represented on screen, isntead of just teh on-screen form
 Set msgNoteText = msg.getItem("Body")
 If Format(Date - 1, "dddd") = "Sunday" Then
 
 msg.ReplaceItemValue "Subject", "AM Consolidated DSR" & " " & Date - 3
 
  msgNoteText.AppendText "Attached is the AM Consolidated DSR" & " " & Date - 3
 
 
 Else
 
 msg.ReplaceItemValue "Subject", "AM Consolidated DSR" & " " & Date - 1
  
  msgNoteText.AppendText "Attached is the AM Consolidated DSR" & " " & Date - 1
 End If
 
 
 Set SendTo = msg.ReplaceItemValue("SendTo", "")
 
 rs.Open "tblAttendeeList", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
 
 Do While Not rs.EOF
   If Not IsNull(rs!Email) Then
     strEmail = rs!Email
     SendTo.AppendToTextList strEmail
   End If
   rs.MoveNext
 Loop
 
 rs.Close
 Set rs = Nothing
 
 msg.Save True, True
strEmail = msg.noteID 'save it so we can reopen it
newMessage.Close
Set msg = Nothing
'now that the record is completely out of the system, we can open it again so that all our changes actually display
Set msg = mailbox.getDocumentByID(strEmail) 'retrieve from disk again
NotesUI.EDITDOCUMENT True, msg 'and redisplay it
 
 
End Sub

Open in new window

0
 
komskexAuthor Commented:
Getting A type mismatch error from this line


 Set msgNoteText = msg.GETITEM("Body")
0
 
qwaleteeCommented:
That should be
Set msgNoteText = msg.getFirstItem("Body")
0
 
komskexAuthor Commented:
Getting Error Notes Error - This operation is not allowed whele a dialog box is displayed.  

Also the email list is not loading , or the subject or the body.  
0
 
qwaleteeCommented:
What line gives the error?
0
 
komskexAuthor Commented:

Sorry

NotesUI.EDITDOCUMENT True, msg 'and redisplay it

0
 
komskexAuthor Commented:
Automation Error
Object is not connected to server
0
 
qwaleteeCommented:
Replace
NotesUI.EDITDOCUMENT True, msg 'and redisplay it
 
With
Set draftMsg = mailbox.getDocumentByID(strEmail) 'retrieve from disk again
If draftMsg Is Nothing Then
  Msgbox "Unable to retrieve message " + strEmail + " form disk. Please find it at the end of your Drafts folder"
Else
  MsgBox "Successfully retrieved message " + strEmail + " form disk. Attempting to open it. If this fails, please find it at the end of your Drafts folder"
  NotesUI.EDITDOCUMENT True, draftMsg 'and redisplay it
End If
 

Set draftMsg = mailbox.getDocumentByID(strEmail) 'retrieve from disk again
If draftMsg Is Nothing Then
  Msgbox "Unable to retrieve message " + strEmail + " form disk. Please find it at the end of your Drafts folder"
Else
  MsgBox "Successfully retrieved message " + strEmail + " form disk. Attempting to open it. If this fails, please find it at the end of your Drafts folder"
  NotesUI.EDITDOCUMENT True, draftMsg 'and redisplay it
End If
 

Open in new window

0
 
komskexAuthor Commented:
I did the above and

The msg box pops up
Successfully retrived message b5a6  .......

I click ok

Then i get a Run time error 7412

Notes Error - This Operation is not allowed while a Dialog box is displayed

Then i hit debug
NotesUI.EDITDOCUMENT True, draftMsg 'and redisplay it
is highlighted




0
 
qwaleteeCommented:
Was there actually a Notes dialog box displayed at that time?
0
 
komskexAuthor Commented:
What is a notes Dialog box ? I mean i had my calendar open and my inbox, that's it ?
0
 
qwaleteeCommented:
Like File->Database-Open, which opens a modal dialog box, or lilke File->Preferences->User preferences

When a modal dialog is open, you can't "click" on Notes.  The client UI is tied up. When this occurs, some of the external APIs are alos unavailable, particularly OLE Automation -- CreateObject("Notes.xxxxx"). Usually, COM objects -- CreateObject("Lotus.xxxxx") -- will succeed, because unlike the OLE interface, they communicate directly with the underlying API code, not using the client as an interface.
0
 
komskexAuthor Commented:
Nothing like that is Open so I don't really know what to say here ? Oh well.  Should i be referencing Lotus notes in access ? I am, just want to make sure if i should.  
0
 
qwaleteeCommented:
If you can, I would use Lotus.NotesSession instead of Notes.NotesSession. The only downside is that you may have to supply a password.

However, NotesuiDocument is ONLY available via Notes., not Lotus., because BY DEFINITION it has a user interface, which means it is using the lcinet, i.e., Notes, not an invisible API. As such, you need to use it with Notes.NotesSession.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now