开发者

Trying to derive from SMTPClient

I am using a CreateUserWizard, which if a MailDefinition is created on it, will look for the default SMTPClient as defined in the configuration section.

I would like to use this configuration section, however the password I want to use is encrypted.

I am attempting to derive from SMTPClient(recommended by another generous poster in previous question) my attempt at implementing is below:

public class MySmtpClient: SmtpClient
    {
       public MySmtpClient() : base()
        {
            MySmtpClient mySmtpClient = new MySmt开发者_运维技巧pClient();
            NetworkCredential nc = CredentialCache.DefaultNetworkCredentials;
            nc.Password = DecryptMyPassword(nc.Password);
            mySmtpClient.Credentials = nc;

I still haven't gotten that part working - but when I do - how do I make it so that the CreateUserWizard uses my derived object to send mail versus the default SMTPClient object?

Thank you!


Handle OnSendingMail event of CreateUserWizard.

In the event handler, use MySmtpClient and cancel the default client by setting e.Cancel = true;

protected void CreateUserWizard_SendingMail(object sender, MailMessageEventArgs e)
    {
        //cancel default handling.
        e.Cancel = true;

        MySmtpClient myClient = new MySmtpClient();
        //fill details and send mail.
    }

Hope this helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜