Developer forum

Forum » Templates » E-mail marketing, template tags

E-mail marketing, template tags

Paul Sørensen
Reply

I need to send out emails to all my users, containing username and password (I know this is a bad idea ;)).

My idea was to create a page with template tags (UserEmail,UserPassword), and use the e-mail marketing module in OMC to send out the mails to a user group.

I haven't been able to find any documentation on which tags are usable regarding e-mail templates. I don't care if I have to use e-mail marketing center, Newsletter v3 or the old newsletter module, but is it in any way possible to send out emails containing the users email and password and / or string from a custom field on the user.


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Paul,

 

You cannot use the Email Marketing module to this effect without some custom code. The reason is, that the user information tags on the page are pre-rendered and the password is not one of the recipient tags available.

 

The best way (and only way, if you don't want to use "Send user details" in User Management) to do this is by creating some custom code. Either by doing a Ribbon extention or a custom module that does something like this:

 

        public bool SendEmails(Dynamicweb.Modules.UserManagement.Group group)
        {
            var recipients = new Dynamicweb.EmailMessaging.RecipientCollection();
            var message = new Dynamicweb.EmailMessaging.Message();

            // Build email html content. Note the tags MyUserTags.UserName and MyUserTags.Password. They are used later!
            message.HtmlBody = "<html><body>Username: <!--@MyUserTags.UserName--><br />Password: <!--@MyUserTags.Password--></body></html>";
            message.Subject = "Your credentials";

            foreach (var user in group.Users)
            {
                // Setting up the recipient
                var recipient = new Dynamicweb.EmailMessaging.Recipient();
                recipient.EmailAddress = user.Email;
                recipient.Name = user.Name;
                
                // Adding the tags from content
                recipient.TagValueCollection.Add("MyUserTags.UserName", user.UserName);
                recipient.TagValueCollection.Add("MyUserTags.Password", user.Password);

                recipients.Add(recipient);
            }

            // Create EmailHandler and prepare message and recipients
            var handler = new Dynamicweb.EmailMessaging.MessagingHandler(message, recipients);

            // Start the send process
            // This process is started in separate threads in the background.
            // Method handler.Process() returns a bool indicating whether the process was started correctly.
            return handler.Process();
        }

 

Hope this helps :)

 

- Jeppe

 

You must be logged in to post in the forum