how to change mail body dynamicaly

Posted by Ankitsrist under ASP.NET on 2/22/2013 | Points: 10 | Views : 1266 | Status : [Member] | Replies : 7
hello,
i have been assigned a task to send the greeting email automaticaly to the employees who have a upcoming birthday through our employee management system, i have created mail body and mail coding using gmail credentials but problem is that our team leader has told that mail body should change dynamicaly means for every employee images in the greeting mail should change, she has given us 6 different greeting, so how to do the same....please help




Responses

Posted by: Ranjeet_8 on: 2/22/2013 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,
System.Net.Mail; //Include This NameSpace 

MailMessage MyMailMessage = new MailMessage();
MyMailMessage.From = new MailAddress("abc@gmail.com");
MyMailMessage.To.Add("xyz@in.com");
MyMailMessage.Subject = "Subject Line goes here";
MyMailMessage.IsBodyHtml = true;

MyMailMessage.Body = "<table><tr><td>" + txtName.Text + txtGreet_Body.Text + txtContents.Text + "</td></tr></table>";

SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");
SMTPServer.Port = 587;
SMTPServer.Credentials = new System.Net.NetworkCredential("abc@gmail.com", System.Configuration.ConfigurationSettings.AppSettings["pwd"].ToString());
SMTPServer.EnableSsl = true;
try
{
SMTPServer.Send(MyMailMessage);
Response.Redirect("ABC.aspx");
}
catch (Exception ex)
{
}


Please Mark As Answer if this helps you.

.

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 2/22/2013 [Member] Starter | Points: 25

Up
0
Down
thanks sir for ur reply but that i already done, i have used external html file for mail body...and i want to change image of it for different users.. how to implement this funda

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Murugavelmsc on: 2/22/2013 [Member] Starter | Points: 25

Up
0
Down
use database....

Regards,
Murugavel S
murugavel.sadagopan@gmail.com
http://murugavelmsc.blogspot.in/

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 2/22/2013 [Member] Starter | Points: 25

Up
0
Down
here is my sample code
StreamReader reader = new StreamReader(Server.MapPath("~/HTMLPage.htm"));

string readFile = reader.ReadToEnd();
string myString = "";
myString = readFile;
myString = myString.Replace("$$Admin$$", "ankit");
myString = myString.Replace("$$CompanyName$$", "cnet infotech");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("ankitsaxena22@rediffmail.com");
msg.To.Add("ankitsaxena2011@india.com");
msg.Subject = TextBox3.Text;
msg.Body = myString.ToString();
msg.IsBodyHtml = true;
SmtpClient smtp=new SmtpClient();

smtp.Host ="smtp.gmail.com";
smtp.Port=587;
smtp.Credentials =new System.Net .NetworkCredential("mailid@gmail.com", "password");
smtp.EnableSsl =true ;
smtp.Send(msg)

my htmlpage.htm page is as follows
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<body >
<img src="images/Sunset.jpg" alt="" height ="300" width ="300"/>
<div style = "border-top:3px solid #EB5E00">&nbsp;</div>
<table >
<tr>
<td><b><span style = "font-family:Arial;font-size:10pt">Dear:</span></b></td>
<td>$$Admin$$</td>
</tr>
<tr>
<td><b><span style = "font-family:Arial;font-size:10pt">CompanyName:</span></b></td>
<td>$$CompanyName$$</td>
</tr>
</table>
</body>
</html>


Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 2/22/2013 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this,
Implement this with your code.
myString = myString.Replace("$$UserImage$$", "ImageName-From-DataBase.jpg");

<img src="images/$$UserImage$$" alt="" height ="300" width ="300"/>


Please Mark As Answer if this helps you

.

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 2/22/2013 [Member] Starter | Points: 25

Up
0
Down
thanks, now m getting new problem image is not displaying in email

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 2/25/2013 [Member] [MVP] Gold | Points: 25

Up
0
Down
try this,

<img src="http://www.abc.com/images/$$UserImage$$" alt="" height ="300" width ="300"/>


Please Mark As Answer if this helps you

.


Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response