Send mail without providing NetworkCredentials in c#
I wanted to know if it's possible to send mails without 开发者_运维技巧providing network credentials? Thanks
You'll almost certainly need to specify the credentials somewhere unless you are on a trusted network. However, you can configure the username and password in web.config if you dont want to construct a NetworkCredentials object in code.
<system.net>
<mailSettings>
<smtp>
<network
host="smtp.example.com"
port="portNumber"
userName="username"
password="password" />
</smtp>
</mailSettings>
</system.net>
It can work only on servers that allow anonymous sending.Check if yours is one such server
Typically mail servers accept only mail for their local accounts only and don't allow relaying to other domains unless you authorize as local user.
You can send email to any address by finding it's mail server (using MX domain record from DNS) and sending directly using SMTP. This is done typically by mail servers. You can set-up your own mailserver which allows relaying from your ip address (address used by your application) and you can send e-mail to any mailbox.
精彩评论