c# - How to Set SMTP Client in POSTAL MVC not in WEB.Config -


i have problem when using postal mvc in project. hosting services company requires me set smtp client config in code not in web config.

how ?

i hope can give me solution

thank you.

i had same problem. there no reference on official postal documentation, nor how-to. here goes one:

  1. create smtpclient instance custom configuration
  2. create postal.emailservice instance using constructor takes 2 arguments (viewenginecollection, func «smtpclient»)
  3. now can send email using custom smtpclient configuration calling emailservice.

here goes 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); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -