Developer forum

Forum » Integration » Sending emails to imported result from ERP

Sending emails to imported result from ERP

Asim Shahzad
Reply

Hi,

We have a situation where users which have created their accounts on DW are disabled by default means "AccessUserActive" is false.Then all the newly created users are sent to ERP where they are registered and then users using the ERP will enable them.

Then from DW we are asking for users which were enabled in last 24 hours and update the "AccessUserActive" for the enabled users in DW DB. We also need to send email to recently enabled users which we got back from ERP. I was thinking to use email functionality in user provide but after reading about it, i found that it is for passwords if we generate them.

Does anyone have any idea how i can get the enabled users and send them email that they are active now ?

I will really apperciate your suggestions.

Regards

Asim


Replies

 
Nicolai Pedersen
Reply

Hi Asim

I guess you have something custom to query ERP for users to enable them. At that time when you enable them, you must have a user object.

Using that, you can easily create an email and send it using the API - something like this:

bool sendSucceded;

            using (var mailMessage = new MailMessage())
            {
                //Find user
                var user = Security.UserManagement.User.GetUserByID(123);

                //Create a template instance
                var template = new Rendering.Template("Users/UserActivated.cshtml"); //Template stored in /Files/Templates/Users/UserActivated
                //Set tags from the user
                template.SetTag("Name", user.Name);

                //Create a message and set the body to the result of the template rendering
                mailMessage.Subject = "This is a test mail";
                mailMessage.From = new MailAddress("noreply@dynamicweb-cms.com", "John Doe");
                mailMessage.To.Add("someone@gmail.com");
                mailMessage.IsBodyHtml = true;
                //mailMessage.Body = "<h1>Hi John</h1>Here is your message.";
                mailMessage.Body = template.Output();
                mailMessage.BodyEncoding = Encoding.UTF8;
                mailMessage.SubjectEncoding = Encoding.UTF8;
                mailMessage.HeadersEncoding = Encoding.UTF8;

                //Send the mail message
                sendSucceded = EmailHandler.Send(mailMessage);
            }

            if (sendSucceded)
            {
                //Log to /Files/System/Log/MyMails
                LogManager.Current.GetLogger("/MyMails").Info("Mail successfully sent");

            }
            else
            {
                //Log to /Files/System/Log/MyMails
                LogManager.Current.GetLogger("/MyMails/Error").Error(("ERROR: Mail not sent"));
            }

BR Nicolai

 
Asim Shahzad
Reply

Hi Nicolai, 

Thanks for your prompt response. can you point me to right direction where i can see how i can do a custom query to ERP. 

Is it that i need to write a customer batch or integration activity ? I am really new to this, i will really apperciate if you can point me to right direction.

 

Regards

Asim Shahzad

 
Nicolai Pedersen
Reply

Hi Asim

In your first question, how much of that do you have implemented yet?

The integration point can be many things and done i many ways - see the docs here: https://doc.dynamicweb.com/documentation-9/integration

 
Asim Shahzad
Reply

Hi Nicolai,

I have not started on it yet, i am just trying to find out what are the existing approches and after that i will start the implementation.

For now i thought i will create a data integration activity with source as XML provider and destination as user provider. This way i can get a list of users which got enabled until this point i have no problem but as i mentioned i need to send emails to users right after running this activity.

I couldnt find if there is any way i can hook it to the activity or if this is not a good way to do it. 

In the end it will be a batch which will run several times a day.

Regards

Asim

 

 

 

You must be logged in to post in the forum