Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have a requirement where i need to send an email alerts to few resources. That part of programming is completed. Here the twist is, i used 2 Event Handlers for this task (1. PreSave Event Handlers and 2. PostSave Event Handlers).

I have separated the Email Sending code logic into one method in (Email.cs) and calling that method in both Event Handler pages (PreSave.cs and PostSave.cs).

But my requirement is i have to send an email from while both event handlers triggered but while using PreSAve, i want BODY as STUDENTID, STUDENT NAME fields and field values and when i use PostSave, i want STUDENT_COURSE and STUDENT_PERCENTAGE in the body.
Please help me on how to do it? Any help will be appreciated.

Below is the code of line i am strucked to deal with (This line is in PreSAve and PostSave.cs):

EmailMethod.SendMail(this.FirstName, this.LastName, "Here i want to add about the mail body");

What I have tried:

I have tried creating a parameter (Name: String BODY) in EmailMethod.cs. But i am not sure how to enter the fields in between the body?
Posted
Updated 8-Jul-16 2:59am
v3
Comments
Madhu Nair 7-Jul-16 2:49am    
You can pass mail content in html format or in plain text to the BODY parameter.
Member 8010354 7-Jul-16 2:51am    
I didn't understand. Can you please elaborate this point?
Madhu Nair 7-Jul-16 2:52am    
can you post the method you are using for sending mail?
Member 8010354 7-Jul-16 3:38am    
I have posted the line where i am struck. Please let me know if this is hard to understand and estimate to provide solution will share the complete code.
Madhu Nair 7-Jul-16 5:46am    
Please post the whole code written in the method
EmailMethod.SendMail

1 solution

Hi
Put your email template in any text file. with some variable like ~Name~ ,~Address~ etc; read it and replace the variable with values like

C#
private string GetBody(string FilePath,string Name,string Address)
{

  Return File.ReadAllTexT(FilePath).Replace("~Name~",Name).Replace("~Address~",Address);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900