Autor Thema: HTML File (Template) im Backend in Notes importieren und versenden  (Gelesen 4668 mal)

Offline Legolas

  • Senior Mitglied
  • ****
  • Beiträge: 446
  • Geschlecht: Männlich
Hallo Forum,

bin heute per Zufall auf diesen Knowledgebase Eintrag (http://www-01.ibm.com/support/docview.wss?uid=swg21098323) der IBM gestoßen, den ich sehr interessant finde.
Ich hatte seit längerem immer wieder mal die Situation, dass ich HTML Dateivorlagen per Notesmail versenden musste.
Dies geht auf sehr umständlichen oder sehr einfachem Wege.

Hier der einfache Weg.
In drei einfachen Beispielen wird erklärt, wie ein HTML File im Backend in ein Notesdokument importiert werden kann um diese dann zu versenden.


Using a local HTML file

The following agent sends an HTML file from the local file system (server's hard drive):


Code
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesMIMEEntity
Dim header As NotesMIMEHeader
Dim stream As NotesStream

Set db = s.CurrentDatabase
Set stream = s.CreateStream
s.ConvertMIME = False ' Do not convert MIME to rich text
Set doc = db.CreateDocument
doc.Form = "Memo"
Set body = doc.CreateMIMEEntity
Set header = body.CreateHeader("Subject")
Call header.SetHeaderVal("HTML message") ' this is the subject
Set header = body.CreateHeader("SendTo")
Call header.SetHeaderVal("user@us.ibm.com")
'The file named below is located on the Domino server because the scheduled agent runs on the Domino server
Call stream.Open("c:\newsletter.html")
Call body.SetContentFromText(stream, "text/HTML;charset=UTF-8", ENC_IDENTITY_7BIT)
Call doc.Send(False)
s.ConvertMIME = True ' Restore conversion

Using dynamic HTML content

The following agent builds an HTML file dynamically. It is also possible to add dynamic content into the HTML as demonstrated.

Notice that the stream.WriteText method uses the pipe ( | ) string delimiter rather than quotation marks. This usage makes it easier to place quotation marks directly into the string. Also, the WriteText lines are separated for easier reading, but they could be concatenated together.

The example code contains EOL_CRLF characters to make the message source properly formatted. This is important because many spam filters block improperly formatted MIME messages.

Code
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesMIMEEntity
Dim header As NotesMIMEHeader
Dim stream As NotesStream

Set db = s.CurrentDatabase
Set stream = s.CreateStream
s.ConvertMIME = False ' Do not convert MIME to rich text

Set doc = db.CreateDocument
doc.Form = "Memo"
Set body = doc.CreateMIMEEntity
Set header = body.CreateHeader("Subject")
Call header.SetHeaderVal("HTML message")
Set header = body.CreateHeader("To")
Call header.SetHeaderVal("user@us.ibm.com")

Call stream.writetext(|<HTML>|)
Call stream.writetext(|<body bgcolor="blue" text="white">|)
Call stream.writetext(|<table border="2">|)
Call stream.writetext(|<tr>|)
Call stream.writetext(|<td>Hello World!</td>|)
Call stream.writetext(|</tr>|)
Call stream.writetext(|</table>|)
user$ = s.CommonUserName 'if scheduled agent this returns the name of the server
'Below uses the ampersand (&) to concatenate user$
Call stream.writetext(|<br><font size="+5" color="red">| & user$ &|</font>|)
Call stream.writetext(|</body>|)
Call stream.writetext(|</html>|)
Call body.SetContentFromText(stream, "text/HTML;charset=UTF-8", ENC_IDENTITY_7BIT)
Call doc.Send(False)
s.ConvertMIME = True ' Restore conversion - very important


Using a prompt for subject, name(s), and HTML file

Code
Sub Initialize
Dim uiwk As New NotesUIWorkspace
Dim s As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim body As NotesMIMEEntity
Dim header As NotesMIMEHeader
Dim stream As NotesStream
Dim vname As Variant
Dim vfile As Variant
Dim ssubject As String
Dim snames As String
Dim sfile As String

ssubject = CStr(InputBox("Please enter a subject","Subject input dialog"))
vname = uiwk.PickListStrings(PICKLIST_NAMES,True)
vfile = uiwk.OpenFileDialog(False,"Please select the HTML file to import")
ForAll names In vname
Set db = s.CurrentDatabase
Set stream = s.CreateStream
s.ConvertMIME = False ' Do not convert MIME to rich text
Set doc = db.CreateDocument
doc.Form = "Memo"

Set body = doc.CreateMIMEEntity
Set header = body.CreateHeader("Subject")
Call stream.Open(vfile(0))
Call body.SetContentFromText(stream, "text/HTML;charset=UTF-8", ENC_IDENTITY_7BIT)
Call header.SetHeaderVal(ssubject) ' this is the subject
Set header = body.CreateHeader("SendTo") 'alternatively you can use "BlindCopyTo" instead of "SendTo"
Call header.SetHeaderVal(names)
Call doc.Send(False)
s.ConvertMIME = True ' Restore conversion
End ForAll
End Sub 
Arbeite klug, nicht hart.

Offline Tode

  • Moderatoren
  • Gold Platin u.s.w. member:)
  • *****
  • Beiträge: 6.883
  • Geschlecht: Männlich
  • Geht nicht, gibt's (fast) nicht... *g*
Dann kanntest Du diesen best practices Artikel[/url] nicht?
Gruss
Torsten (Tode)

P.S.: Da mein Nickname immer mal wieder für Verwirrung sorgt: Tode hat NICHTS mit Tod zu tun. So klingt es einfach, wenn ein 2- Jähriger versucht "Torsten" zu sagen... das klingt dann so: "Tooode" (langes O, das r, s und n werden verschluckt, das t wird zum badischen d)

 

Impressum Atnotes.de  -  Powered by Syslords Solutions  -  Datenschutz