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.
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.
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"!
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.
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.
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.
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);
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=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!
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
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
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
Bingo! Thanks Dirk!
The Member.New event is exactly what I was looking for.
[code]Member.New += new Member.NewEventHandler(MemberNew);
void MemberNew(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
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
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
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.
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
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=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
http://umbraco.codeplex.com/WorkItem/View.aspx?WorkItemId=21611
Regards,
/Dirk
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.
is working on a reply...