Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

receive the email from Lotus Note and detach the attachment?

Posted on 2002-07-19
18
Medium Priority
?
457 Views
Last Modified: 2010-07-27
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
.................

0
Comment
Question by:mingichu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
18 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7166846
Go to www.angelfire.com/realm/vb-shared/index.html under "say OLE to COM..." topic.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7166849
Specially:
"Say OLE!, to COM with Lotus Notes 4.x & 5.x. - Save Attachments" topic ;)
0
 

Author Comment

by:mingichu
ID: 7169371
I tried it
I don't have "Notes Dominal Object" in my project reference. Do I need to download it from somewhere? Thanks!!!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7169447
what version of Notes do you use?
0
 

Author Comment

by:mingichu
ID: 7169470
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7169506
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
 

Author Comment

by:mingichu
ID: 7169537
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7169591
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
 

Author Comment

by:mingichu
ID: 7172353
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7172431
If itm.Type = RichText Then   ''*** I am stuck here!!
 my mistake:
declaring
Const RichTex = 1
should do the trick.
let me know.
Cheers
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 400 total points
ID: 7172454
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
 

Author Comment

by:mingichu
ID: 7172624
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7172658
I saw what you say before but i haven't problems with it.
I will do a check.
0
 

Author Comment

by:mingichu
ID: 7172801
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7172840
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7172943
I saw a code to send mail with Notes (with VB) at internet that not allow us to save the attachment.
Strange thing...
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8031880
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
 

Expert Comment

by:SpideyMod
ID: 8095538
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 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