Sending emails with merge fields in BBIS

If you aren’t familiar with merge fields in BBIS then please check JR’s blog here.

Please note this is not a fully working example. It has code excerpts that will hopefully help you on your way. If you have any questions please post them below and I will respond to them within a day.

Sending emails from within BBIS isn’t a difficult thing at all.

Try
    'MyContent.ConfirmationEmailTemplateID comes from my custom object that holds the editors properties
    Dim template As New EmailTemplate(MyContent.ConfirmationEmailTemplateID)

    'our email is based on our template. save it.
    Dim email As New EMail(template)
    email.Save()

    Dim recipientName = String.Concat(Me.txtStep3FirstName.Text, " ", Me.txtStep3LastName.Text)
    Dim emailAddress = txtStep3Email.Text

    email.Send(emailAddress, recipientName, email.GetUserConstituentId(), email.GetUserId(), Nothing, Me.Page)
Catch ex As Exception
    lblError.Visible = True
    lblError.Text = ex.Message
End Try

Now if you want to send an email with merge fields in it then it’s going to a little different.

You would make the call to sending the email like so:

    Dim args as BBNCExtensions.API.Transactions.PaymentArgs = Me.CreateEmailArguments()

    With args
        .EmailAcknowledgementId = MyContent.TemplateID        
        .CustomMergeData = 'a new instance of your class that inherits BBNCExtensions.API.Merge.MergeData
        .EmailAddress = MyContent.sendTo
    End With

    MyBase.API.Emails.EmailJob.SendConstituentEmail(Me.Page, args.EmailAcknowledgementID, Me.API.Users.CurrentUser.RaisersEdgeID, args.CustomMergeData)

Now the only problem with what is above is that it only works with non-nested merge fields. For instance if you have a person objec that has multiple phones

on it then you can’t use the API for sending emails. Instead you have to use the first way listed above to send the email but with one minor change.

You would add this:

     Dim provider() As MergeFieldsData = { New MergeFieldsData(mergeData.ToArray()) }

And then where Nothing is currently being passed in you would pass in provider. So it would look something like this:

     Try
         Dim template As New EmailTemplate(MyContent.ConfirmationEmailTemplateID)
         'our email is based on our template.  save it.
         Dim email As New EMail(template)
         email.Save()

         Dim recipientName = String.Concat(Me.txtStep3FirstName.Text, " ", Me.txtStep3LastName.Text)
         Dim emailAddress = txtStep3Email.Text
         Dim provider() As MergeFieldsData = {New MergeFieldsData(mergeData.ToArray())}

         email.Send(emailAddress, recipientName, email.GetUserConstituentId(), email.GetUserId(), provider, Me.Page)
     Catch ex As Exception
         lblError.Visible = True
         lblError.Text = ex.Message
     End Try

On a side note to check the status of your emails you can always check the database tables: EMAIL, EMAILJOB.

There are more but those two helped me out the most in troubleshooting errors.

Also please note every email must have a link to a privacy page and an unsubscribe page. If you need help creating those then take a lookey look here.

Happy coding.

Open-mouthed smile

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s