At the February 2024 Aptify Developer RoundTable a great question came up, How do I send a magic link in a message?
Magic link, what were talking about is a link to your website that has an encrypted query string or url parameter were the page’s server can then retrieve the value, decrypt, validate and then do what ever it needs to.
To do this, we need a Message Part.
The scenario below is that an email with a magic link is sent out to members when there address is flagged as a bad address. Idea being members could (within a limited time) update there address without logging in. Stay tuned, as the how to send this message when the address is set to bad is coming next.
Message Part
The message part will be a Script message part which allows you to write a vb script to return a string. Aptify also give you a simple way to retrieve the ID of the record the message is being generated for so you can query for additional details.
Field | Value |
---|---|
Name | Bad Address Update Magic Link_sa |
Description | Generates the Bad Address Update a magic link anchor tag. |
Type | Script |
Category | Address Blocks |
Script | see below |
Using dt As System.Data.DataTable = oDataAction.GetDataTable(
oResponse.MarkupString(
System.Convert.ToString("SELECT ID, AddressID FROM vwPersons WHERE ID = <%ID%>")
)
)
If dt IsNot Nothing AndAlso dt.Rows.Count = 1 Then
Dim obj As String = String.Format("{{ ""PersonID"": {0}, ""AddressID"": {1}, ""Timestamp"": ""{2}"" }}", dt.Rows(0)(0), dt.Rows(0)(1), System.DateTime.Now)
' FOR TESTING ONLY
'Aptify.Framework.ExceptionManagement.ExceptionManager.Publish(New System.Exception(obj))
Dim encrypted As String = Aptify.Framework.Web.Common.WebCryptography.Encrypt(obj)
Dim sLink As String = String.Format("<a href=""https://mysite.organization.org/bad-address-magic-link?x={0}"" style=""color: #007bff;"" target=""_blank"">Update Address</a>", encrypted)
oResponse.WriteText(sLink)
End If
End Using
Message Template
Now that we have a message part we need to add it to our message template.
Field | Value |
---|---|
Name | Bad Address w/Update Magic Link_sa |
Description | Bad address with a magic link for member to update there address. |
Category | Use an appropriate category |
Subject | Simplify Aptify - Your Address Is Invalid |
Default Message System | Use your orgs message system |
Default Message Source | Persons |
To Type | Field |
From Name | The From Name |
From Email | The From Email |
HTML | see below |
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="[Your email description here]">
</head>
<body style="background-color: #eee; padding-top: 32px; padding-bottom: 32px;">
<center>
<table width="650" border="0" cellspacing="0" cellpadding="0" style="margin: 0px auto;">
<tr>
<td style="background-color: #fff; padding: 16px;">
<p>Hello <<FirstLast>>,<p>
<p>Sorry to inform you but your address has been flag as a "bad address" and we need you to review/update your address.
Please use following link to update your address: <<_APTIFY_PART_29 "Bad Address Update Magic Link_sa">>.
<td>
</td>
</table>
</center>
</body>
</html>
There you have it, you now have a message part on a message template that will generate the magic link.
Aptify Clients
Continue the conversation on the Community Forums.