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:
- create smtpclient instance custom configuration
- create postal.emailservice instance using constructor takes 2 arguments (viewenginecollection, func «smtpclient»)
- 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
Post a Comment