Inviare una mail da un’agente notes con allegati
Supponiamo di avere un documento in una vista, e che questo documento abbia una serie di allegati. La funzione qui sotto prende in ingresso:
- l’indirizzo email
- Il messaggio
- Il documento che contiene gli allegati
- Il nome della vista dove cercare il documento
Sub sendMail(mail As String, strMessaggio As String, docInput As NotesDocument, viewInput as NotesView) Dim docMemo As notesdocument Dim bodyitem As notesRichTextItem Dim dbCurrent As NotesDatabase Dim Sessione As NotesSession Dim rt As NotesRichTextItem Dim obj As NotesEmbeddedObject Dim i As Integer Dim viewAllegati As NotesView Dim dbInput As NotesDatabase Dim nome As String Dim word As NotesEmbeddedObject Dim rtitem As NotesRichTextItem Dim docAllegato As NotesDocument Dim dc As NotesDocumentCollection On Error Goto ProcessError Set dbInput = docInput.ParentDatabase Set Sessione = New NotesSession Set dbcurrent = Sessione.CurrentDatabase 'Creo il documento Mail Set docMemo = New NotesDocument(dbCurrent) docMemo.Form = "Memo" docMemo.Sendto = mail docMemo.Recipients = mail docMemo.Subject = Set rt = New NotesRichTextItem( docMemo, "Body" ) 'Ciclo su tutti gli allegati Set viewAllegati = dbInput.GetView(viewInput) If Not viewAllegati Is Nothing Then Set dc = viewAllegati.GetAllDocumentsByKey(docInput.UniversalID, False) Set docAllegato = dc.GetFirstDocument While Not ( docAllegato Is Nothing ) Set rtitem = docAllegato.getfirstitem("body") If ( rtitem.Type = RICHTEXT ) Then Forall o In rtitem.EmbeddedObjects If ( o.Type = EMBED_ATTACHMENT ) Then Call o.ExtractFile( "c:\temp\" & o.Source ) 'Qui inserisco l'allegato nel documento della mail Set obj = rt.EmbedObject ( EMBED_ATTACHMENT,"","c:\temp\" & o.Source) End If End Forall End If Set docAllegato = dc.GetNextDocument(docAllegato) Wend End If Call rt.appendtext(strMessaggio) Call docMemo.send(True) Print "sendMail terminata correttamente" Exit Sub ProcessError: Print "Errore " & Err & " , " & Error & " in sendMail alla riga " & Erl End Sub |
Leave a Reply