We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem with Mail Merge - Aspose.Network.Mail

I have made this class for this scope:

  1. Create message from a template message;
  2. Replace all field (#fieldExample#), with datasource

This code run successfully only for the subject. The body of my email remain with original merge field ("FirtName").

During the debug, the mergeField located in the body are correctly merged, but after I save the message (view last row of the following code) the mergeField are incomplete

Public Function MailMerge(ByVal listOfMergeField As List(Of MergeField), _

ByVal PathMessage As String, _

ByRef msgError As String) As Boolean

Dim netSmtpMailSection As New MailSettingsSectionGroup

Dim config As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath)

netSmtpMailSection = config.GetSectionGroup("system.net/mailSettings")

Dim SMTP As String = netSmtpMailSection.Smtp.Network.Host

Dim client As New Aspose.Network.Mail.SmtpClient(SMTP)

Dim message As Aspose.Network.Mail.MailMessage

message = Aspose.Network.Mail.MailMessage.Load(PathMessage, Aspose.Network.Mail.MessageFormat.Msg)

message.IsBodyHtml = True

message.BodyEncoding = System.Text.Encoding.Default

message.From = New Aspose.Network.Mail.MailAddress("contoso@microsoft.com", "My Web Site", System.Text.Encoding.UTF8)

message.To.Add("contoso@microsoft.com")

Dim dt As DataTable = New DataTable

'Inserisco tante colonne per quanti sono i campi MergeField

For Each mergeField In listOfMergeField

dt.Columns.Add(mergeField.mergeFieldName, GetType(String))

Next

'Istanzio una riga e valorizzo le colonne in base ai valori dei campi

Dim Row As DataRow = dt.NewRow

For Each mergeField In listOfMergeField

Row(mergeField.mergeFieldName) = mergeField.mergeFieldValue

Next

dt.Rows.Add(Row)

Dim engine As New TemplateEngine(message)

Dim messages As New MailMessageCollection()

messages = engine.Instantiate(dt)

message = messages.Item(0)

message.Save(PathMessage, Aspose.Network.Mail.MessageFormat.Msg)


This message was posted using Page2Forum from Performing Mail Merge - Aspose.Network for .NET

Hi,

Thanks for considering Aspose.

I am sorry, I could not reproduce the bug. Could you please test the attached sample at your end and see if the message body contains #FirstName# or its value. I could not see how you are setting MailMessage.Body or HtmlBody property in your sample code.

I don't set the message body, because I read it from a template message (see the attached file) by the method "Aspose.Network.Mail.MailMessage.Load(pathmessage, messageFormat)". This template contains the fields #Protocollo#, #Appaltatore#, #Appaltatore1#.

When I run my web site with debug, and I move the mous over the object "message", after the method "engine.Instatiate(dt)", the fields are correcly valued. But when the e-mail arrive in my mailbox, these values doesn't appears.

Attached to this email you find my template message

Thank you in advace for your attention

Best regards

Hi,

By loading the template message from disk, the body still contains #Protocollo# and other tokens instead of their values. I have added this in our bug tracking system (ID: 11552) and informed the developers about it. We will notify you when there is a fix available. Sorry for the inconvenience.

As an alternative, could you please create the new message using MailMessage class and load the Subject, Body etc from a text file?