Reputation: 254
This is my C# code which sends an email to a given email address, It works nearly fine But The problem is that I get only the text as Tags, but the color is not shown in the background at all (which is supposed to be DodgerBlue), Any help with why this is happening? (I think the problem may be caused by the body itself...)
private bool SendEmail(string BodyText)
{
var fromAddress = new MailAddress("[email protected]", "HackerOne Scanner");
var toAddress = new MailAddress("[email protected]", "Title");
const string fromPassword = "Password";
const string subject = "Important Update";
string body = "<h3 style=\"background - color:DodgerBlue; padding: 25px 25px 25px 25px; text - align: center; \">"+BodyText+"</h3>";
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
};
using (var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
})
{
try
{
message.IsBodyHtml = true;
smtp.Send(message);
return true;
}
catch
{
return false;
}
}
}
Thanks in advance.
Upvotes: 0
Views: 802
Reputation: 1044
Trim the spaces
string body = "<h3 style=\"background-color:DodgerBlue; padding: 25px 25px 25px 25px; text-align: center; \">"+BodyText+"</h3>";
Upvotes: 1