|
Hai All,
Could anyone please tell me how to configure Local SMTP server and how to send mail through C# code.
Regards,
Rajesh KAndepu
|
|
|
|
|
There are lots of samples here on CodeProject: Google will find them for you.
|
|
|
|
|
I am getting "Failure sending mail" and it said Socketexception unable to connect.
I am using windows8 and visual studio 2010. And I have ran the web application from visual studio. Should i do anything else ..
Below is my code..
<pre lang="c#">
string from = "no-reply@retro.com";
string to = "rajeshvec2006@gmail.com";
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new System.Net.Mail.MailAddress(from, "test", System.Text.Encoding.UTF8);
mail.Subject = "test";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "hai";
mail.BodyEncoding = System.Text.Encoding.UTF8;
SmtpClient client = new SmtpClient();
client.Host = "Localhost";
client.Send(mail);
</pre>
Could you please help me in this..
|
|
|
|
|
SmtpClient client = new SmtpClient();
client.Host = "Localhost";
Do you have a SMTP server running on your local PC? Without it this will not work.
|
|
|
|
|
I have configured SMTP mail in IIS server 7.0. IS that enough or I have to install anything explicitly. Don't mind I am asking you minute details because this is the first time I am handling this SMTP servers.
Regards,
Rajesh
|
|
|
|
|
OK, but that does not answer my question.
|
|
|
|
|
Let me explain about my senario.....
I have a windows7 machine and IIS installed on it....I have hosted a ASP.Net website in it.. I have to send email notifications from the registered users on my website...I do not want to use gmail or any other smtp server...I have to send the mails from the site with some random mailid like noreply@something.com....How can I achieve it....
|
|
|
|
|
You still have not answered the question, "do you have an SMTP server running on 'localhost'.".
|
|
|
|
|
NO i do not have a smtp server running.. I want help about this...
|
|
|
|
|
Then you cannot send an email to that port. Google for " free SMTP" to find one.that you can use.
|
|
|
|
|
Can you suggest me any open source smtp servers..
|
|
|
|
|
|
http://www.systemnetmail.com/[^] is a good place to start.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am getting "Failure sending mail" and it said Socketexception unable to connect.
I am using windows8 and visual studio 2010. And I have ran the web application from visual studio. Should i do anything else ..
Below is my code..
<pre lang="c#">
string from = "no-reply@retro.com";
string to = "rajeshvec2006@gmail.com";
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(to);
mail.From = new System.Net.Mail.MailAddress(from, "test", System.Text.Encoding.UTF8);
mail.Subject = "test";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "hai";
mail.BodyEncoding = System.Text.Encoding.UTF8;
SmtpClient client = new SmtpClient();
client.Host = "Localhost";
client.Send(mail);
</pre>
Could you please help me in this..
|
|
|
|
|
I see that the SMTP client is not configured properly. I had a very similar problem while try to send an email from my C# application.
I resolved that by configuring the SMTP client correctly. Please make sure you set all the necessary SMTP client properties, like,
- Host
- Port
- UseDefaultCredentials
- EnableSsl
- ServicePoint
Check your credentials(if you are not using the Default credentials)
|
|
|
|
|
The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
I am running this application in my local machine. So no heavy DB queries and all. I have pasted my code below. This error happens on con.Open()
string connString = ConfigurationManager.ConnectionStrings["DL"].ConnectionString;
using (SqlConnection con = new SqlConnection(connString))
{
SqlCommand cmd = new SqlCommand("spGetAllEmployees", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Employee employee = new Employee();
employee.ID = Convert.ToInt32(rdr["ID"]);
employee.Name = rdr["name"].ToString();
employee.Gender = rdr["gender"].ToString();
employee.City = rdr["city"].ToString();
employee.DateOfBirth = Convert.ToDateTime(rdr["dateofbirth"]);
Employees.Add(employee);
}
}
Help me to resolve pls.
Thanks, Geetha
|
|
|
|
|
|
I tried setting it. but did not work.
<connectionstrings>
<add name="DL" connectionstring="Data Source=(localdb)\v11.0;Initial Catalog=Sample;Integrated Security=True;Connection Timeout=30"
="" providername="System.Data.SqlClient">
|
|
|
|
|
Did you set ConnectionTimeout and/or CommandTimeout?
If so, what values did you use?
Can you post the code of where you set these values?
Have you further details of the exception? i.e. What object has timed out?
|
|
|
|
|
The timeout error happens with connection object. Initially, i didnt have connection timeout value in the connection string. after reading prev msg, i set the connection timeout value in connection string and the value of conn string is as follows
<connectionstrings>
<add name="DL" connectionstring="Data Source=(localdb)\v11.0;Initial Catalog=Sample;Integrated Security=True;Connection Timeout=30"
="" providername="System.Data.SqlClient">
Also, I tried to see the values of
Console.WriteLine("State: {0}", con.State);
Console.WriteLine("ConnectionTimeout: {0}",
con.ConnectionTimeout);
while there was a time out error thrown on con.Open(), I hover over the state and timeout value in the above statement to see the values, the timeout was set to 30 and the state was closed.
|
|
|
|
|
System.InvalidOperationException was unhandled by user code
HResult=-2146233079
Message=Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
Source=System.Data
StackTrace:
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
|
|
|
|
|
<connectionStrings>
<add name="DL" connectionString="Data Source=(localdb)\v11.0;Initial Catalog=Sample;Integrated Security=True;Connection Timeout=30"
providerName="System.Data.SqlClient" />
</connectionStrings>
|
|
|
|
|
|
Thank you for your message. I will give you the clear picture of what the issue is.
I have written a small app to test MVC. In my application, I created MVC project and used View and controller from the MVC project itself but for the model, I created a class library project and a class within that project will query the database using ADO.net and get the details and store it in an object and the object would be passed to MVC application.
In this application only, I am not able to fetch the data from the database. I used localdb from the sql server bundled with VS2013.
I created a separate console application and tested the database access. It works perfectly fine. I get back the response from the database.
|
|
|
|
|
How/where to set the Anti-MIME-Sniffing header X-Content-Type-Options to 'nosniff' for all aspx pages
|
|
|
|