Reputation: 11
mailItem.HTMLBody = "
Dear IT Dept.
You have received a new "+ comboBox3.Text + " priority task to complete from " + textBox1.Text + ". Please save the attached file and fit the task in to your schedule.
Once completed please contact the " + textBox2.Text + " for comfirmation the task is completed to thier expectations.
The Task is as follows:
" + richTextBox1.Text + "
Kind Regards,
" + textBox1.Text + "
";I basically want to highlight the text/combo boxes or at least change their font color. Annoyingly you can't see the html code I used but it should be pretty obvious but I tried using the font color...with no luck. can't see where I'm going wrong
Upvotes: 0
Views: 107
Reputation: 9690
Did you mean :
mailItem.HTMLBody = "<html><body><p>Dear IT Dept.</p> <p>You have received a new task to complete from " + textBox2.Text + " Please check the attached file and fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to thier expectations.</p>";
?
In your version, "textbox2.txt" will be manipulated as a string, it won't be "parsed". In mine it's a control on your form and we put its text content in the mail.
Edit : you asked how to emphase the variable, here is a example : Try something like
mailItem.HTMLBody = "<html><body><p>Dear IT Dept.</p> <p>You have received a new task to complete from <strong>" + textBox2.Text + "</strong> Please check the attached file and fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to thier expectations.</p>";
The "strong" tag around your variable will put the name in bold.
Upvotes: 0
Reputation: 7073
var mailItem= new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp server addess");
mailItem.From = new MailAddress("[email protected]");
mailItem.To.Add("it-department@???.co.uk");
mailItem.Subject = string.Format("You have a new task from {0}", comboBox3.Text);
mailItem.To = "";
mailItem.Body =string.Format("<html><body><p>Dear IT Dept.</p> <p>You have received a new task to complete from {0} Please check the attached file and fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to their expectations.</p>",textBox2.txt);
attachment = new System.Net.Mail.Attachment(@"\\??-filesvr\shares\Shared\+++++Web Projects+++++\????\IssueReport.txt");
mailItem.Attachments.Add(@"\\??-filesvr\shares\Shared\+++++Web Projects+++++\??\IssueReport.txt");
mailItem.IsBodyHtml = true;
// Optional Items based on your smtp server.
/* SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("username", "password");
SmtpServer.EnableSsl = true;*/
SmtpServer.Send(mailItem);
MessageBox.Show("mail Send");
Upvotes: 0
Reputation: 14618
There is no HTMLBody
property on the MailMessage
class (assuming this is what you're using?).
It's just Body.
You would do something like this:
mailItem.Body = string.Format("<html><body><p>Dear {0}.</p>", comboBox3.Text);
Etc...
Upvotes: 1
Reputation: 1777
You need to have:
mailItem.HTMLBody = "<html><body>... from " + textBox2.Text + " Please ...";
instead of
mailItem.HTMLBody = "<html><body>... from (textBox2.txt) Please ...";
Upvotes: 1
Reputation: 1038
I can see that you try to put value of textBox2.txt
. Your mistake is that wrote textBox2.txt as a string content. So you can achive this with using string.Format
method.
You should to change it with this:
mailItem.HTMLBody = string.Format("<html><body><p>Dear IT Dept.</p> <p>You have received a new task to complete from ({0}) Please check the attached file and fit the task in to your schedule.</p><p> Once completed please contact the provided contactee for comfirmation the task is completed to thier expectations.</p>", textBox2.Text);
Notice that textBox2.Text and
{0}
element.
Note: You also wrong with syntax of TextBox.Text property.
Upvotes: 1