Merging mail in C # with n copies
You can use Aspose.Word to handle the Word object model without having to install office (to use interop) where the program should run, I use Aspose.Word to create word documents.
Aspose link: http://www.aspose.com/categories/file-format-components/aspose.words-for-.net-and-java/default.aspx
And it works pretty well :)
source to share
I did it in Java - (broken link) working example here with source code.
Here's the idea: use MS-Word to design and create the document you want to send. Save it as XML (either Word-ML or the new .docx format). Then, using a text editor, replace the fields in the document with placeholder tags, such as @@ NAME for the name, and @@ ADDRESS for the address, etc. Tag names don't matter.
Then create replacement logic - either with XSLT or even a simple string based replacement function, and iteratively replace the tags with the actual data values. Save each modified document.
Easy peasy.
You can use the same design in C # - it would actually be EASIER.
source to share
I'm not sure if you want to launch the mailbox or copy the template. I can't help you with C #, but this VBA snippet might give you some ideas.
strDir = CurrentProject.Path
strMailmergeDataFilename = strDir & Format(Now, "yymmdd_hhnnss") & ".txt"
' Create CSV from database for use with mailmerge '
' This is a separate function that simply exports the sql '
' ExportSQLToCSV SQL, strMailmergeDataFilename '
'Open merge template '
Set objWordDoc = GetObject(strDir & MergeDocumentFilename, "Word.Document")
objWordDoc.Application.Visible = True
'Format:=0 ''0 = wdOpenFormatAuto'
'Add the data source '
objWordDoc.MailMerge.OpenDataSource _
Name:=strMailmergeDataFilename, ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=0, _
Connection:="", SQLStatement:="", SQLStatement1:=""
'Type some text at a bookmark, you could use .range property '
Selection.Goto What:=wdGoToBookmark, Name:="signaturetext"
Selection.TypeText Text:="You are here"
'Run mailmerge '
objWordDoc.MailMerge.Destination = 0 '0 = wdSendToNewDocument'
objWordDoc.MailMerge.Execute
objWordDoc.Application.ActiveDocument.PrintPreview
source to share