Solved

Email Missing Signature

Posted on 2007-11-27
20
774 Views
Last Modified: 2013-12-18
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
Comment
Question by:komskex
20 Comments
 
LVL 84
Comment Utility
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
 
LVL 63

Expert Comment

by:SysExpert
Comment Utility
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
 

Author Comment

by:komskex
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
 

Author Comment

by:komskex
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
 

Author Comment

by:komskex
Comment Utility
Getting A type mismatch error from this line


 Set msgNoteText = msg.GETITEM("Body")
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
That should be
Set msgNoteText = msg.getFirstItem("Body")
0
 

Author Comment

by:komskex
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
What line gives the error?
0
 

Author Comment

by:komskex
Comment Utility

Sorry

NotesUI.EDITDOCUMENT True, msg 'and redisplay it

0
 

Author Comment

by:komskex
Comment Utility
Automation Error
Object is not connected to server
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
 

Author Comment

by:komskex
Comment Utility
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
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
Was there actually a Notes dialog box displayed at that time?
0
 

Author Comment

by:komskex
Comment Utility
What is a notes Dialog box ? I mean i had my calendar open and my inbox, that's it ?
0
 
LVL 31

Expert Comment

by:qwaletee
Comment Utility
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
 

Author Comment

by:komskex
Comment Utility
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
 
LVL 31

Accepted Solution

by:
qwaletee earned 125 total points
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now