I am trying to send email through email template to user but It is always replacing the user merge fields by org admin's user name instead of targetobjectID user.
Org admin : luke wright
Email template Body :
Dear {!User.Name} ,
Hearty Congratulations on this beautiful occasion. May your marriage bring great joy, love and passion in your life. I wish to God to bless you with a wonderful marriage and a happy life ahead.
Thanks and Regards.
{!Organization.Name}
OrgWideEmailAddress owa = [select id, DisplayName, Address from OrgWideEmailAddress limit 1];
List<Messaging.SingleEmailMessage> allmsg = new
List<Messaging.SingleEmailMessage>();
Messaging.SingleEmailMessage mail = new
Messaging.SingleEmailMessage();
mail.setTemplateID('00X0S000000iBYB'); // Template Id
mail.setSaveAsActivity(false);
mail.setTargetObjectId('0050S0000023KS9'); // UserId Name: John Doe
mail.setOrgWideEmailAddressId(owa.id);
allmsg.add(mail);
Messaging.sendEmail(allmsg,false);
Issue: Dear {!User.Name}
should be replace by john doe while it is replacing by luke wright and email goes to correct user i.e. john doe
P.S. User's merge fields is not replacing by that record ID