How to send an "Email Marketing" in ASP . NET?

Asked

Viewed 95 times

0

At first: I am sending an email using the standard ASP . NET service as code below

public class SendMail
{
    public bool SendEmail(MailModel mail, string subject, string body)
    {
        try
        {
            string emailRemetente = System.Configuration.ConfigurationManager.AppSettings["EmailRemetente"].ToString();
            string senhaRemetente = System.Configuration.ConfigurationManager.AppSettings["SenhaRemetente"].ToString();

            MailMessage message = new MailMessage(emailRemetente, mail.To, subject, body);
            Console.WriteLine(message.IsBodyHtml);
            message.IsBodyHtml = true;
            message.BodyEncoding = UTF8Encoding.UTF8;

            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.EnableSsl = true;
            client.Timeout = 100000;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            client.Credentials = new NetworkCredential(emailRemetente, senhaRemetente);

            client.Send(message);

            return true;
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
            return false;
        }
    }
}

where the Mailmodel parameter will be filled as:

public class MailModel
{
    public string From { get; set; }
    public string To { get; set; }
}
  1. I want to know how to send email marketing (personalized emails using HTML), I just add a reference to the body?
  2. Is there any framework or plugin for ASP . NET that does this?
  • I couldn’t understand exactly what your doubt is

1 answer

1


You already have everything done in your code, there is no need for a framework for sending.

You set message.IsBodyHtml = true; this causes email servers to read the syntax of your email as HTML. So just create an HTML file and pass it to the method SendEmail(in the body parameter).

string emailMarketing = File.ReadAllText("caminho_do_arquivo_html");
SendEmail(MailModel,subject,emailMarketing);

I only advise you to be careful with the semantics of your HTML because each email server (Gmail, Hotmail, Yahoo and so on) accepts or does not accept HTML tags, you need to create an Email Marketing with an HTML that is generic and will work on most email servers.

I asked a question "What is the best practice of styling an email body" and helped me a lot because the email services were "deleting" the tags that they didn’t accept and my HTML was getting all disfigured, a read in the answers will help you a lot !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.