How to get the CreateUserWizard to email using the DisplayName instead of From email address?

Hi,

I'm trying to work out how to get the CreateUserWizard to email using the DisplayName (or equivalent) so that the recipient sees a name (e.g. Ben Miller) instead of an email address in the From field of their email client.  In my CreateUserWizard control I have tried putting a name (e.g Ben Miller) in like this:

    <asp:CreateUserWizard...>
    <MailDefinition BodyFileName="~/BodyFile.txt"
            Subject="Welcome new User" From="user@domain.com, Ben Miller">
    </MailDefinition>
    ...
    </asp:CreateUserWizard>

I have also tried using the web.config file, but neither of these seem to use the DisplayName

    <mailSettings>
      <smtp from="user@domain.com, Ben Miller">
        <network host="mail.domain.com" password="plugh" userName="user@domain.com"/>
      </smtp>
    </mailSettings>


In the .NET Framework Class Library doco I have found MailAddress, however I can't get this style of email to work with the MailDefinition

MailAddress Class
The MailAddress class is used by the SmtpClient and MailMessage classes to store address information for e-mail messages.

A mail address is composed of a User name, Host name and optionally, a DisplayName. The DisplayName can contain non-ASCII characters if you encode them.

MailAddress..::.DisplayName Property
Display names that contain non-ASCII characters are returned in human-readable form. Use the ToString method to get the encoded form of the DisplayName.

Some software programs that are used to read e-mail display the DisplayName property value instead of, or in addition to, the e-mail address.

and it gives an example like this:

MailAddress from = new MailAddress("ben@contoso.com", "Ben Miller");

Anyone got an idea how to get this working with the CreateUserWizard?

Thanks.
0
YdoIbother
8/6/2008 12:49:35 PM
asp.net.security 27051 articles. 1 followers. Follow

2 Replies
1041 Views

Similar Articles

[PageSpeed] 39
Get it on Google Play
Get it on Apple App Store

You can hook into the SendingMail event of the wizard

Protected Sub PasswordRecovery1_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles PasswordRecovery1.SendingMail
        Dim s As String = e.Message.Body.Trim
        'create a new mail here and send it

e.Cancel = true   'cancel the wizard's mail
End Sub
 


Regards,
Prashant


Dont forget to click "Mark as Answer" on the post that helped you.
0
Prashant
8/6/2008 2:25:16 PM

 Thanks Prashant, not the easy answer I was hoping for, but at least you've cleared this up for me.

0
YdoIbother
9/5/2008 12:47:33 PM
Reply: