Automatically Resending Failed Emails

Example

In all versions after 1.6, failed mail is stored in the Failed Mail Archive database. The Failed Mail Archive database is located in the MGI Data folder of the virtually hosted client that originally attempted to send the email. Emails can be automatically re-attempted using a dynamic database search and mgiSendMail.

MGI Tags

  • mgiDatabaseUpdate
  • mgiGet
  • mgiPOP
  • mgiSearchDatabase
  • mgiSendMail
  • mgiSet

Steps

  1. Open any high-traffic page in a text editor.
  2. Enter a dynamic search in a variable.
  3. Save the high-traffic page.
  4. Create a results format file in a text editor.
  5. Enter the mgiSearchResults variable.
  6. Save the results format file.
  7. Create a results template file in a text editor.
  8. Enter the mgiSendMail tag, variables and mgiDatabaseUpdate tag.
  9. Save the results template file.
  10. FTP the high-traffic page, results format file and results template file to the web server running MGI.
  11. Access the high-traffic page.


Step 1: Open any high-traffic page in a text editor.

Open a high-traffic page (from the root level of your site) in a text editing program that allows you to view and modify HTML. The "automatic" process to re-attempt failed emails occurs when a user accesses a page with the dynamic search. Note: do not enter the dynamic search code on a page until a Failed Mail Archive database has been created by a failed mail. If the Failed Mail Archive database does not exist, AN ERROR WILL OCCUR and the page will not display! If you are uncertain about the existence of a failed mail archive, put a page containing an mgiEditDatabase tag in the MGI Data folder and access it. The mgiEditDatabase tag will display all databases in the folder. If the "MGI Failed Mail Archive" is in the list, then you may safely insert the dynamic search on the page. If you are unsure, enter the dynamic search code on a test page first.

Warning: A Failed Mail Archive database must exist or the dynamic database search code will cause an error and the page will not display.

Step 2: Enter a dynamic search in a variable.

The dynamic search will not display on the page, so it can be entered anywhere. To automatically re-attempt failed emails, enter the dynamic search code exactly as it appears below, except for the "searchFormatFileLocation" parameter of the mgiSearchDatabase tag. The field names and database names are the same across all sites.
 
Here is a brief overview of the function of the dynamic search code: The "SearchResults" variable hides the result of the dynamic search so that it does not display on the page. The "mgiSearchDatabaseAction=performSearch" variable sets the action of the dynamic search. The "field=To" variable searches the "To" field of the MGI Failed Mail Archive database. The "mgiSearchDatabaseResultsLimit=3" variable determines the number of failed emails to re-attempt during each search. In this example, 3 emails are re-attempted during each search. To change the number of emails that are re-attempted, change the "3" to another number in the "mgiSearchDatabaseResultsLimit=3" variable.
 
The mgiSearchDatabase tag identifies the database file and table that contain the failed emails. For pages at the root level of a web site, the databaseFileLocation is "MGI Data/MGI Failed Mail Archive" and the tableName is "MGI Failed Mail Archive". The searchFormatFileLocation parameter must exists, but the contents of that file are not used in the dynamic search. Therefore, enter the name of a file that exists in the searchFormatFileLocation parameter. The results format file and the results template file will be created in subsequent steps. Therefore, enter "rf_failedmail.txt" in the resultsFormatFileLocation parameter and enter "rt_failedmail.txt" in the resultsTemplateFileLocation parameter.
<mgiSet name="SearchResults">

<mgiSet name="mgiSearchDatabaseAction=performSearch">
MGI Use Only
</mgiSet>

<mgiSet name="field=To">
	*
</mgiSet>

<mgiSet name="mgiSearchDatabaseResultsLimit=3">
MGI Use Only
</mgiSet>

<mgiSearchDatabase 
databaseFileLocation="MGI Data/MGI Failed Mail Archive"
tableName="MGI Failed Mail Archive" 
searchFormatFileLocation="index.html"
resultsFormatFileLocation="rf_failedmail.txt" 
resultsTemplateFileLocation="rt_failedmail.txt">

</mgiSet>
        

Step 3: Save the high-traffic page.

Save the changes you have made to the high-traffic page.

Step 4: Create a results format file in a text editor.

Create a new, blank page in a text editing program.

Step 5: Enter the mgiSearchResults variable.

Enter the "mgiSearchResults" variable using an mgiGet tag. The "mgiSearchResults" variable is the only element on the results format file.
<mgiGet name="mgiSearchResults">

Step 6: Save the results format file.

Save the results format file and name it "rf_failedmail.txt", the value of the resultsFormatFile parameter in the mgiSearchDatabase tag in the dynamic search.

Step 7: Create a results template file in a text editor.

Create a new, blank page in a text editing program.

Step 8: Enter the mgiSendMail tag, variables and mgiDatabaseUpdate tag.

On the results template file, enter the mgiSendMail tag, variables, and mgiDatabaseUpdate tag exactly as they appear below.
 
Here is a brief overview of the function of the tags. The mgiSendMail tag sends each email from the Failed Mail Archive database as it is found. The "field=To" variable, "keyfield=ID" variable, and mgiDatabaseUpdate tag deletes the email from the database. If the email cannot be sent, it is added to the end of the failed mail database.
<mgiSendMail to="<mgiGet name="To">"
from="<mgiGet name="From">"
subject="<mgiGet name="Subject">"
mailServer="<mgiGet name="Mail Server">"
replyTo="<mgiGet name="Reply To">"
fromName="<mgiGet name="From Name">"
attachmentFileLocation="<mgiGet name="Attachment File Location">"
gmtOffset="<mgiGet name="GMT Offset">">

   <mgiGet name="Message">

</mgiSendMail>

<mgiSet name="field=To">
</mgiSet>

<mgiSet name="keyfield=ID">
    <mgiGet name="ID">
</mgiSet>

<mgiDatabaseUpdate 
databasefilelocation="MGI Data/MGI Failed Mail Archive"
tablename="MGI Failed Mail Archive" 
mode="deleterecords">

Step 9: Save the results template file.

Save the results template file and name it "rt_failedmail.txt", the value of the resultsFormatFile parameter in the mgiSearchDatabase tag in the dynamic search.

Step 10: FTP the high-traffic page, results format file and results template file to the web server running MGI.

Upload the high-traffic page, results format file and results template file to the web server running MGI.

Step 11: Access the high-traffic page.

Each time the dynamic search is accessed on the high-traffic (or test) page, the first 3 emails in the Failed Mail Archive are re-attempted. If an email cannot be sent, it is added back to the Failed Mail Archive database. Periodically, you may want to check the Failed Mail Archive for emails with fatal errors. To check the Failed Mail Archive database, place a file with an mgiEditDatabase tag in the MGI Data folder and access it with a browser. Using the mgiEditDatabase interface, you can delete or update the information in those emails so that they will be successfully sent during the next search of the Failed Mail Archive.


[Return to the Using Web Based Email Menu]


[User Guide Main Menu] [Understanding MGI Menu] [Using MGI Menu] [Referencing MGI Menu]