Changing the MailDefinition.BodyFileName of PasswordRecovery control programmatically?

Posted on 2007-10-16
Last Modified: 2008-01-09

I have a passwordRecovery control and a custom text file which contains the Body of the email.  I get the email fine if I specify the File name at design time in the MailDefinition of the PasswordRecovery control:

 <MailDefinition From="" Subject="Your New Password" BodyFileName="PasswordMail.txt">  

However I need to set the Text file at runtime based on the users current theme.  I have tried to do this in the PasswordRecovery's sendingMail event but this just sends the default email out.  ie (doesn't apply the text file)  here's what i'm doing:

Protected Sub PswdRecovery_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles PswdRecovery.SendingMail
        Me.PswdRecovery.MailDefinition.BodyFileName = "PasswordMail.txt"
    End Sub

The text file is in the same dir as the page so this isn't the problem.  Any ideas?
Question by:fizzer666
    LVL 96

    Accepted Solution

    Have you tried changing the BodyFileName before the SendingMail event?


    Author Comment

    I tried putting it in the page load event but only on a load eg:

    If Not Page.IsPostBack Then
                Me.PswdRecovery.MailDefinition.BodyFileName = miscFunctions.getThemeDir & "/PasswordMail.txt"
      End If

    This didn't work unless I take it out of the if condition.  At least now it works but this will fire multiple times.  Is there an event I can use which will only fire this once?
    LVL 96

    Expert Comment

    by:Bob Learned
    Is there a problem if the BodyFileName is set twice?


    Author Comment

    It doesn't effect the outcome but I just wondered whether there was a more efficient way.  In this instance, your right, I suppose it's not much of a perfomance hit.  Thanks for your help.  

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now