1
I am having the following problem when sending an email with my application, at the time of opening the email, the Outlook provider modifies the template tags by putting the "x_" at the beginning of attributes name and id tag.
For example a normal input would look like this: <input type="text" name="nome" />.
But he gets like this when he gets to the inbox: <input type="text" name="x_nome" />
.
Someone once had a similar problem?
My Email Sending Class:
public static class MailHelper
{
private static string Login = ConfigurationManager.AppSettings["LoginEmail"].ToString();
private static string Senha = ConfigurationManager.AppSettings["PassEmail"].ToString();
private static string Url = ConfigurationManager.AppSettings["Url"].ToString() + "/Account/ChangePassword/";
public static async Task EnviarMensagem(string Para, string Assunto, string Codigo, string Nome, string Token)
{
//Template html
var html = CreateBody(Codigo, Nome, Token);
try
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress(Login); //Remetente
msg.To.Add(new MailAddress(Para)); //Destinatario
msg.Priority = MailPriority.High;
//msg.Attachments.Add(attachment);
msg.AlternateViews.Add(html);
msg.IsBodyHtml = true;
msg.Subject = Assunto;//Assunto
//msg.Body = html.ToString();
SmtpClient smtp = new SmtpClient("smtp-mail.outlook.com", 587);
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(Login,Senha); ;
smtp.Send(msg);
// Log de acesso a nova senha
Log l = new Log
{
Evento = "Lembrar Senha",
Mensagem = "Solicitação de nova senha",
Pagina = "Lembrar Senha",
Cpf = Codigo,
};
LoggerRepository log = new LoggerRepository();
log.Save(l);
}
catch (Exception ex)
{
Log l = new Log
{
Evento = "Lembrar Senha",
Mensagem = ex.Message,
Pagina = "Lembrar Senha",
Cpf = Codigo,
};
LoggerRepository log = new LoggerRepository();
log.Save(l);
throw ex;
}
}
// Cria o corpo do E-mail
public static AlternateView CreateBody(string Codigo, string Nome, string Token)
{
string template = "";
//Lê o template
using (var reader = new StreamReader(HostingEnvironment.MapPath("~/App_Data/Template/RememberPassword.txt")))
{
template = reader.ReadToEnd();
}
string imagem = HttpContext.Current.Server.MapPath("~/Content/logo_sabesprev.PNG");
LinkedResource attachment = new LinkedResource(imagem);
attachment.ContentId = "EmbeddedLogo";
attachment.ContentType.MediaType = MediaTypeNames.Image.Jpeg;
attachment.ContentLink = new Uri("cid:" + attachment.ContentId);
//Seta os parametros no template do E-mail
template = template.Replace("{Nome}", Nome);
template = template.Replace("{Url}", Url);
template = template.Replace("{Codigo}", Codigo);
template = template.Replace("{Token}", Token);
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(template, null, MediaTypeNames.Text.Html);
htmlView.LinkedResources.Add(attachment);
return htmlView;
}
}