i have a problem when using POSTAL MVC in my Project. My hosting services company requires me to set smtp client config in code not in web config.
How to do that ?
I hope someone can give me a solution
Thank you.
i have a problem when using POSTAL MVC in my Project. My hosting services company requires me to set smtp client config in code not in web config.
How to do that ?
I hope someone can give me a solution
Thank you.
I had the same problem. There is no reference on the official Postal documentation, nor an How-to. So here goes one:
Here goes a complete sample code:
dynamic email = new Email("Example");
email.To = "webninja@example.com";
email.FunnyLink = DB.GetRandomLolcatLink();
SmtpClient client = new SmtpClient("mail.domain.com");
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("user@domain.pt", "somepassword");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Port = 25;
client.EnableSsl = false;
Postal.EmailService emailService = new Postal.EmailService(new ViewEngineCollection(), () => client);
emailService.Send(email);
To Add to Rafael's answer. If you use
Postal.EmailService emailService = new Postal.EmailService(new ViewEngineCollection(), () => client);
you might get this error: Email view not found for [name for he email template]. Locations searched
because new Postal.EmailService(new ViewEngineCollection(), () => client)
creates emailService with empty view engine. Use ViewEngines.Engines
inplace of new ViewEngineCollection()
(as sugested by @Houssam Hamdan in comment above) to use razor view engine.
Complete line:
Postal.EmailService emailService = new Postal.EmailService(ViewEngines.Engines, () => client);