I wanted to know if it's possible to send mails without providing network credentials? Thanks
-
Are you sending email through exchange? – SquidScareMe Apr 26 '11 at 09:44
3 Answers
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>

- 3,234
- 23
- 32
-
The same thing i am doing,but my problem is, the mail module in my project will use more than 20 users,hence i can't configure each user in my web.config , – user725110 Apr 26 '11 at 10:02
-
1This question might be of help http://stackoverflow.com/questions/4363038/setting-multiple-smtp-settings-in-web-config – Adam Pope Apr 26 '11 at 10:09
-
The method that you suggested will require each account to be configured in web.config whenever a new account is created,but that is not possible. – user725110 Apr 26 '11 at 10:20
-
2So your system has users and they can each send email from their own email account? Then you'll need to ask each user for their account credentials, store them in a database and get them back out when sending the emails - creating an instance of NetworkCredentials and passing it to the Credentials property of your SmtpClient. – Adam Pope Apr 26 '11 at 10:27
-
Asking each user for their credentials will raise a security issue,can you suggest me any other method – user725110 Apr 26 '11 at 10:30
-
1Then what you want is near-impossible - certainly is with Gmail. You cannot send anonymous mail unless you are on a trusted network and using your own SMTP server on which you have disabled the authentication. Why do you want to send email from your users email accounts? – Adam Pope Apr 26 '11 at 10:33
It can work only on servers that allow anonymous sending.Check if yours is one such server

- 37,194
- 9
- 78
- 82
-
Am using smtp.gmail.com as server,but i dont think that allows anonymous sending – user725110 Apr 26 '11 at 09:51
-
correct, they do not. If they had, all spammers in the world would use their servers to fill your inbox. – jgauffin Apr 26 '11 at 09:52
-
so can u suggest me some anonymous SMTP servers,coz i have one scenario in my project,where i need to send mail as user that comes dynamically from database. – user725110 Apr 26 '11 at 09:55
-
1Check [This](http://technet.microsoft.com/en-us/library/bb124305%28EXCHG.65%29.aspx) – V4Vendetta Apr 26 '11 at 09:57
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.

- 3,122
- 2
- 26
- 36