receive the email from Lotus Note and detach the attachment?

Hi! All experts,

I'm looking for a way to use VB6 detach the attachment file(S) from the Inbox folder of Lotus Notes email to our local/share drive.  We already have codes to create Lotus Notes session,  set the database to send mail from, open the mail file and send an email (pls see below). Now need the help to receive the email and detach the file. Thanks in advance!

============
    Dim NotesSession As Object  
    Dim NotesDb As Object      
    Dim NotesDoc As Object      
    Dim RichText As Object      
    Dim Attachment1 As Object  
    Dim strServerName As String
    Dim strUserDb As String    
    Dim vstrCopy  As String

    strServerName = "XXXXXX/XXX/XX/XXX"
    strUserDb = "ABC.nsf"
    Set NotesSession = CreateObject("Notes.NotesSession")  
    Set NotesDb = NotesSession.GETDATABASE(strServerName, strUserDb)
    NotesDb.OPENMAIL
.................

mingichuAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Richie_SimonettiConnect With a Mentor IT OperationsCommented:
here is correct code:

Sub ReadMail(sPathToSave As String)
Dim View As Object
Dim nDoc As Object
Const RICHTEXT = 1
Const EMBED_ATTACHMENT = 1454
'Dim nDoc2Remove object

Set View = LotusDB.GetView("($Inbox)")
Set nDoc = View.GetFirstDocument

Dim itm As Variant

While Not (nDoc Is Nothing)
    If nDoc.HasEmbedded Then
        Set itm = nDoc.GetFirstItem("Body")
        If itm.Type = RICHTEXT Then
            Dim attch As Variant
            Debug.Print nDoc.GetFirstItem("Subject").Text
            For Each attch In itm.EmbeddedObjects
                If (attch.Type = EMBED_ATTACHMENT) Then
                    attch.ExtractFile sPathToSave & attch.Name
                    Debug.Print attch.Name
                End If
            Next
           
        End If
        'Set nDoc2Remove = nDoc
    End If
    Set nDoc = View.GetNextDocument(nDoc)
'    If Not (nDoc2Remove Is Nothing) Then
'        nDoc2Remove.Remove (True)
'        Set nDoc2Remove = Nothing
'    End If
   
Wend

End Sub
0
 
Richie_SimonettiIT OperationsCommented:
Go to www.angelfire.com/realm/vb-shared/index.html under "say OLE to COM..." topic.
0
 
Richie_SimonettiIT OperationsCommented:
Specially:
"Say OLE!, to COM with Lotus Notes 4.x & 5.x. - Save Attachments" topic ;)
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mingichuAuthor Commented:
I tried it
I don't have "Notes Dominal Object" in my project reference. Do I need to download it from somewhere? Thanks!!!
0
 
Richie_SimonettiIT OperationsCommented:
what version of Notes do you use?
0
 
mingichuAuthor Commented:
Lotus Notes 4.5 (Release 4.5.7 January 19, 1999) Thanks!!

By the way, I have to change the way to open Lotus Notes and email database, don't I? Currently I use "Lotus Notes OLE Types" reference in my project with the codes described in my original question. Thanks!!!
0
 
Richie_SimonettiIT OperationsCommented:
Then, as in article says, you have to replace all strong typed variables with generic "as object".
Makes it sense now? Let me know.
I use that code in a daily basis with version 4.x (which supports OLE) and 5.x (which supports COM) with no problems.
Cheers
0
 
mingichuAuthor Commented:
I see...
But I didn't find check box of "Lotus Dominal Objects" in the Prodject References. Where can I go to find it or download it? I use Lotus Notes 4.5 (Release 4.5.7 January 19, 1999). Thanks!!!
0
 
Richie_SimonettiIT OperationsCommented:
Of course, that's for version 5.x
Set a reference to Lotus Notes Automation classes (notes32.tlb).
It could be reached at windows\system folder or in Notes folder.
0
 
mingichuAuthor Commented:
When I  declared Richtext as Object, at the first run of the While...Wend loop, I got the error 91 at "If itm.Type = Richtext Then..."  The problem: itm.Type is empty.
(Run-time error 91: Object variable or With Block variable not set )
When I declared RichText as Variable, it ran numbers of time inside the loop, and I saw itm.Type =1 and Richtext is empty. But when it ran the 180th time, I got the same error msg (Run-Time error 91)  at the same place.

Confused.... Any hint? Thanks!!
===========================================================
Option Explicit
Private Const EMBEDATTACHMENT = 1454
Public EMBED_ATTACHMENT As Object
Public Sub NotesSaveAttachs(sPathToSave As String)
  Dim NotesSession As Object
  Dim NotesDb As Object
  Dim NotesDoc As Object
  '''Dim RichText As Object
  Dim RichText As Variant
  Dim Attachment1 As Object
  Dim strServerName As String  
  Dim strUserDb As String      
  Dim View As Object
  Dim nDoc As Object
  Dim itm As Variant
  Dim ctr As Long
  Dim attch As Variant

  strServerName = "XXXXX/XX/XX/XXX"
  strUserDb = "ABC.nsf"
  Set NotesSession = CreateObject("Notes.NotesSession")
  Set NotesDb = _
  NotesSession.GETDATABASE(strServerName, strUserDb)
  NotesDb.OPENMAIL

  Set View = NotesDb.GETVIEW("($Inbox)")
  Set nDoc = View.GETFIRSTDOCUMENT
  While Not (nDoc Is Nothing)
    If nDoc.HASEMBEDDED Then
        ctr = ctr + 1
        Set itm = nDoc.GETFIRSTITEM("Body")
        If itm.Type = RichText Then   ''*** I am stuck here!!
           
            For Each attch In itm.EMBEDDEDOBJECTS
                If (attch.Type = EMBED_ATTACHMENT) Then
                    attch.EXTRACTFILE sPathToSave & attch.Name
                End If
            Next          
        End If
    End If  
    Set nDoc = View.GETNEXTDOCUMENT(nDoc)
   
  Wend

End Sub
0
 
Richie_SimonettiIT OperationsCommented:
If itm.Type = RichText Then   ''*** I am stuck here!!
 my mistake:
declaring
Const RichTex = 1
should do the trick.
let me know.
Cheers
0
 
mingichuAuthor Commented:
Thanks!!  I modified the program based on your solution. It ran very well for the most emails.
But, if the emails( and their attachments) in my InBox are sent automately from VB program, (not manually by  another person), I got either:
Run-time error 91 at  "If itm.Type = RichText Then" ,OR run-time error 13 Type-mismatch at "For Each attch In itm.EMBEDDEDOBJECTS" (attch is empty ...)

I checked all the automatic emails and found:  There is a line between the body texts and attachment. It means the attachment is NOT inside the body section of the email. In contrast, regular inbox emails have attachment(s) with the body section.
I guess this is another question.....
0
 
Richie_SimonettiIT OperationsCommented:
I saw what you say before but i haven't problems with it.
I will do a check.
0
 
mingichuAuthor Commented:
You are a great helper!!
As I said, it works very well in most of the emails. It can't work in only a few of emails which are sent automatically.
I'll also check our VB program which creates and sends emails with attachments.
Thanks in advance!!!
0
 
Richie_SimonettiIT OperationsCommented:
This is my send with attach procedure:

Private Sub cmdSend_Click()
Const EMBED_ATTACHMENT = 1454
' Creates a new document/message.
Dim Doc As Object
    Dim NItem As Object
    Set Doc = OLEDB.CreateDocument
    With Doc
        ' creates body of message and populates headers
        Set NItem = Doc.CreateRichTextItem("BODY")
        .Form = "Memo"
        .subject = Text1(2).Text
        .sendto = Text1(0).Text
        .copyto = Text1(1).Text
        .body = Text1(3).Text
        .postdate = Date
        ' if there is files to attach, it does
        If lstFiles.ListIndex <> -1 Then
            Dim i As Integer, UpperLstCount As Integer
            UpperLstCount = lstFiles.ListCount - 1
            For i = 0 To UpperLstCount
                lstFiles.Selected(i) = True
                Call NItem.EmbedObject(EMBED_ATTACHMENT, "", lstFiles.Text)
            Next i
        End If
        .Send False
    End With
End Sub

i just tried it and i can see that line but attachment were saved with no problem.
0
 
Richie_SimonettiIT OperationsCommented:
I saw a code to send mail with Notes (with VB) at internet that not allow us to save the attachment.
Strange thing...
0
 
DanRollinsCommented:
Hi mingichu,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept Richie_Simonetti's comment(s) as an answer.

mingichu, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0
 
SpideyModCommented:
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.