Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 10, 2009 @ 15:11
    Lee Kelleher
    0

    Member.AfterNew event doesn't trigger Member.NewEventHandler

    Hi all,

    Ran into a slight hick-up with the API events of the Member object.

    When a new member is created, I want to be able to send out a couple of emails (to the new user and an admin) ... I've tried to hook this up with the Member.AfterNew event, but since the "AfterNew" is inherited from the CMSNode object I can't directly access the Member object.

    From looking through the source (well, via Reflector), I noticed that there is a Member.NewEventHandler delegate, which is exactly what I need... but I can't figure out which event calls it.

    Any ideas?


    Thanks in advance,
    - Lee

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 10, 2009 @ 15:29
    Dirk De Grave
    0

    Lee,

    Member.MakeNew() fires the New event... not sure if you'd get the member info in the event though, which would probably be mandatory to send the mail to the user.

    Cheers,
    Dirk

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 10, 2009 @ 15:36
    Lee Kelleher
    0

    Bingo! Thanks Dirk!

    The Member.New event is exactly what I was looking for.

    [code]Member.New += new Member.NewEventHandler(MemberNew);

    void Member
    New(Member sender, NewEventArgs e) { }[/code]

    I was getting confused with the naming conventions, was looking around for events that started with "After" or "Before" ... didn't think to look at the (obvious) "New"!

    Thanks again!

    Cheers,
    - Lee

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Mar 10, 2009 @ 15:48
    Ismail Mayat
    0

    Lee,

    Do you now about member controls on codeplex its like Doc2Form only you point it to member type as opposed to doc type? In the past I have fired out emails on member creation with hacked version of it.

    I would have pasted link but codeplex seems to be down but you can get it to from codeplex/umbraco its in bottom right nav.

    Regards

    Ismail

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Mar 10, 2009 @ 16:00
    Lee Kelleher
    0

    Thanks Ismail, I'll take a look once CodePlex is back up.

    The other reason I wanted to use the Member events API is to also capture any members that the admin creates via the back-end. This would covers all my bases.

    Cheers,
    - Lee

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Mar 12, 2009 @ 17:52
    Simon Dingley
    0

    On the same topic can anyone suggest why the member passed to the Member.NewEventHandler has an empty email address. I am trying to send a welcome email to new members when they are created by admins and I can get hold of the member.User.Name but not member.Email or member.User.Email.

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Mar 12, 2009 @ 18:49
    Simon Dingley
    0

    Here is the event handler:
    [code] void Member_New(Member sender, NewEventArgs e)
    {
    try
    {
    // send email to new member
    MailMessage msg = new MailMessage();

    msg.From = new MailAddress("membership@.org" ,"*");
    msg.To.Add(new MailAddress(sender.Email, sender.User.Name));

    msg.Subject = "Welcome to the ";
    msg.IsBodyHtml = false;

    StringBuilder sb = new StringBuilder();
    sb.AppendLine("Dear " + sender.User.Name);
    sb.AppendLine();
    sb.AppendLine("Thank you for becoming a member of *
    .");
    sb.AppendLine("As part of your membership you now have access to a members only area of the website.");
    sb.AppendLine();
    sb.AppendLine("Username: " + sender.LoginName);
    sb.AppendLine("Password: " + sender.Password);
    sb.AppendLine();
    sb.AppendLine("To get started login at the address below:");
    sb.AppendLine("http://www.example.org/members.aspx");
    sb.AppendLine();
    sb.AppendLine("-- ");
    sb.AppendLine("www.example.org");

    msg.Body = sb.ToString();

    SmtpClient client = new SmtpClient();
    client.Send(msg);

    }
    catch (Exception ex)
    {
    Log.Add(LogTypes.Error, sender.Id, "Member: " + sender.Text + " failed to send emails. " + ex.Message);
    }
    }[/code]


    Now the problems seem to be as follows:

    sender.User.Name = the logged in USERS name
    sender.Email = empty string
    sender.LoginName = The new users name not LoginName
    sender.Password = empty

  • Simon Dingley 1474 posts 3431 karma points c-trib
    Mar 12, 2009 @ 23:11
    Simon Dingley
    0

    Update in case anyone is interested or can help me out. Having attached to the process and monitored the member record in the database I can confirm that at the point the Member.NewEventHandler is fired the only data in the database relating to the member seems to be nodeid and LoginName so I'm not likely to get very far with this.

    Why is this? Any suggestions on an alternative method of sending the welcome emails?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 13, 2009 @ 09:07
    Dirk De Grave
    0

    [quote=ProNotion]Update in case anyone is interested or can help me out. Having attached to the process and monitored the member record in the database I can confirm that at the point the Member.NewEventHandler is fired the only data in the database relating to the member seems to be nodeid and LoginName so I'm not likely to get very far with this.

    Why is this? Any suggestions on an alternative method of sending the welcome emails?[/quote]

    I can confirm this. Have been debugging some code to find out what happens in the background...

    If creating user from admin backend:

    -MakeNew() is called, which fires New event, but sadly, the member details are set after execution of MakeNew() in the Save() method on memberTasks (standardTask.cs file).

    Have checked this on the 4.0 release (latest change set), not sure if this is still an issue on the 4.0.1 release and whether this is also the case if creating members using the members control package or asp.net membership controls.

    Don't see an alternative solution atm though.

    Problem will still persist in 4.0.1. Adding a work item for this on Codeplex!

    Cheers,
    /Dirk

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Mar 13, 2009 @ 09:18
  • Craig Cronin 304 posts 503 karma points
    Apr 13, 2014 @ 00:25
    Craig Cronin
    0

    I know this post is old, but I'm having this problem with a version 4.5 site and its killing me.  I'm trying to create members from the admin section and would like to send automatic emails with login details.

    Due to the sensitivity of the data I've changed passwords to clear in the web.config, and I'm capturing the event in visual studio but the password is blank...aarrrggghhh

    Any help would be appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft