Last post Feb 15, 2017 06:44 PM by mgebhard
Feb 14, 2017 11:23 AM|Haider Ali|LINK
Any body help me how we send email in ASp.NEt without using credential
like PHP below code
mail('email@example.com', 'My Subject', $message);
Feb 14, 2017 11:50 AM|PatriceSc|LINK
Being able to really send a mail without any credential will depend on the mail server configuration. The .NET mail class takes it settings from the web.config file (as likely done by PHP as well with its own config file) So you could start with
https://msdn.microsoft.com/en-us/library/w355a94k(v=vs.110).aspx and add at least the host name in the web.config file.
Then try some basic code such as
http://systemnetmail.com/faq/2.1.aspx, What to do next will depend on the behavior or error message you see then. The code shouldn't change but you may have to add more settings in the web.config file.
Edit: if you still have something that works with PHP, check the PHP.ini file for settings:
If you are using the same mail server you should be able to use the same settings in the web.config file.
Feb 14, 2017 11:52 AM|mgebhard|LINK
Passing credentials is up to the SMTP service not PHP or ASP. If your SMTP service requires credentials the you must pass credentials.
Feb 15, 2017 02:24 PM|Haider Ali|LINK
First of All thanks for help me.
1) But face some problem with your given answer on my Post, i use following code in web.config file
<network host="localhost" port="25" defaultCredentials="true" />
2) Following Code in my Action
//create the mail message
MailMessage mail = new MailMessage();
//set the addresses
mail.From = new MailAddress("firstname.lastname@example.org");
//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";
//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
3) But server Give me error
Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25
can again help me resolve this problem .
Feb 15, 2017 02:51 PM|PatriceSc|LINK
Do you really have a SMTP server installed on your machine? It might be also a firewall issue.
Not related but you should be able to use new SmtpClient() without an address (this class will use localhost as you have this already in your web.config file).
Feb 15, 2017 06:41 PM|KathyW|LINK
If you are sending mail from a gmail address, you need to use gmail's server, not localhost (even if you had a mailserver on localhost). And it will require using the mail account's password. An example:
Feb 15, 2017 06:44 PM|mgebhard|LINK
The errors means there's no SMTP service running on localhost (127.0.0.1 port 25). You' need a valid SMTP service to send email.