I had the same problem - a database-based multilanguage application.
Setting the mail body content in the sending_mail event is too late to switch to another mail body file and at that stage it is also imppossible to acces the <%UserName%> and <%Password%> placeholders (see http://blog.dotnet-oldenburg.de/2009/03/23/aspnet-passwordrecovery-control-neues-passwort-programmatisch-auslesen/ for those reading German).
What does work, however, is to
(1) place the password recovery control in a user control (.ascx file).
(2) place the user control in an .aspx file which has an event specified that reacts to a change in language (see http://www.odetocode.com/articles/450.aspx on how to do that).
This has the effect that every time there is a change in language (say, in an associated master page) the .aspx page (and, hence, the .ascx user control) reloads.
Now, all you need to do is to set up a streamer object updating the .txt file for the password-recovery email in the Page_Load event of the user control (see http://aspnet.4guysfromrolla.com/articles/072303-1.2.aspx how to handle streamer objects).
For convenience, I just copy/paste my code from the .ascx file's Page_Load event that works fine for me . I store / update the language information in the Session["WorkingLanguageCode"] dictionary object. Note also that I use the MySQL database system and the related MySQLClient, so you will have to adapt your data extraction logic according to your settings. I just leave it here for illustration purposes...
...
using System.IO; // needed for the text streamer object.
...
protected void Page_Load(object sender, EventArgs e)
{
...
// Get language-specific email text data from cd_page_contents (database table containing all my language-specific data)...
MySQLDatabaseConnection DBConnection = new MySQLDatabaseConnection("CodeListDBConnString");
try
{
DBConnection.connectDB();
//Get Label Data for this page and Working Language Code
string SQL = "SELECT object_type, " + Session["WorkingLanguageCode"] + " FROM `cd_page_contents` WHERE page_name = 'email.passwordrecovery'";
...
MySql.Data.MySqlClient.MySqlDataReader myReader = DBConnection.SelectData(SQL);
string isObjectType;
string isPropertyValue;
if (myReader != null)
{
while (myReader.Read())
{
isObjectType = myReader["object_type"].ToString();
isPropertyValue = myReader[Session["WorkingLanguageCode"].ToString()].ToString();
switch (isObjectType)
{
case "EmailHeading": isEmailHeading = isPropertyValue; break;
case "EmailText1": isEmailText1 = isPropertyValue; break;
case "EmailText2": isEmailText2 = isPropertyValue; break;
case "EmailText3": isEmailText3 = isPropertyValue; break;
case "EmailText4": isEmailText4 = isPropertyValue; break;
case "EmailTextLogin": isEmailTextLogin = isPropertyValue; break;
case "EmailTextPassword": isEmailTextPassword = isPropertyValue; break;
case "EmailSignature1": isEmailSignature1 = isPropertyValue; break;
case "EmailSignature2": isEmailSignature2 = isPropertyValue; break;
default: break;
} // end switch
} // end while
} // end myReader != null
} // end try
catch (MySql.Data.MySqlClient.MySqlException ex)
{
...
}
finally
{
DBConnection.disconnectDB();
}
// rewrite the password recovery email...
string ifFileName = Server.MapPath("~/login/passwordrecoverymail.txt");
//Get a StreamReader class that can be used to read the file
StreamWriter ioStreamWriter = File.CreateText(ifFileName);
ioStreamWriter.WriteLine("<p style=\"font-family: Verdana Ref, Verdana, Arial, Calibri,Helvetica, Sans-Serif; font-size:9pt\">");
ioStreamWriter.WriteLine("<br/>" + isEmailText1);
ioStreamWriter.WriteLine("<br/><br/><br/>" + isEmailText2);
ioStreamWriter.WriteLine("<br/><br/>" + isEmailTextLogin + " <%UserName%>");
ioStreamWriter.WriteLine("<br/><br/>" + isEmailTextPassword + " <%Password%>");
ioStreamWriter.WriteLine("<br/><br/><br/><b>" + isEmailText3 + " </b> " + isEmailText4);
// close streamer...
ioStreamWriter.Close();
// set response email properties
PasswordRecovery_Control.MailDefinition.IsBodyHtml = true;
PasswordRecovery_Control.MailDefinition.BodyFileName = "~/login/passwordrecoverymail.txt";
}
...
That should work.
Don't forget to set the .From property of the email definition as well as your smtp settings in the web.config file.
Well, I hope this is of help to others having a similar headache... just as much as the other contributions on this forum are of help to me.
Have fun!
Wolfgang
(in case of questions, contact me at wolfgang.schwerdt@freenet.de)