简体   繁体   中英

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>

它只能在允许匿名发送的服务器上工作。检查您的服务器是否是这样的服务器之一

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM