I'm tired to send message over SSL with SMTP by i still have an exeption :
"Operation timed out"
My questions is :
How to resolve this problem;
How to send an email behind the firewall !!!
Thanks,
public void SendMessage()
{
SmtpClient client = new SmtpClient("servername.ru.alt001.com");
client.Credentials = new NetworkCredential("ali.mselmi#server.ru","password");
client.Port = 465;
client.EnableSsl = true;
MailMessage message = new MailMessage()
{
Subject = "Test Message",
Body = "Hello, this is a test !!! Kind Regards Ali Mselmi"
};
message.To.Add("ali.mselmi#gmail.com");
message.From = new MailAddress("ali.mselmi#server.ru");
client.Send(message);
}
}
That's the point of a firewall - people can't reach a port behind it unless they're allowed to.
You'll need to contact the firewall owner/admin if indeed that's the problem.
The other possibility is that you have the wrong port number - 465 is the legacy port number for secure smtp - I believe 587 is the recommended port...
Related
I am getting error "operation time out"and it throws me to the exception when i am sending email through my smtp server.I am using the code with gmail smtp and the same code works fine.In smtp details I am using network credential as my username and password i got when i created my email account on my domain and outgoing server and smtp port. following is my code..
protected void send_Click(object sender, EventArgs e)
{
string to = "xyz#gmail.com"; //To address
string from = "xyz#gmail.com"; //From address
MailMessage message = new MailMessage(from, to);
string mailbody = "Welcome to gmail...";
message.Subject = "Sending Email";
message.Body = mailbody;
message.IsBodyHtml = true;
SmtpClient client = new SmtpClient("server host",port);
System.Net.NetworkCredential basicCredential1 = new
System.Net.NetworkCredential("Username ","Password");
client.EnableSsl = true;
//client.Timeout = 10000;
client.UseDefaultCredentials =false;
client.Credentials = basicCredential1;
try
{
client.Send(message);
}
catch (Exception ex)
{
throw ex;
}
}
Because you haven't posted any log data, what you have already tried, and what didn't work, and only giving us the timeout as an outcome, there are a lot of open ended questions to your question. So instead of a specific answer, all I can do is give you vague directions what you need to do, to resolve your issue.
There can be a lot of issues with this sort of thing.
You write that this code performs correctly with another server, if I understand you correctly?
I would check:
A, Am I 100% sure my server connection string is correct? Also port wise?
B, Am I sure the ports are open for this communication to happen?(Check the firewalls are open)
C, Am I that there isn't some sort of version or configuration that is different between the gmail smtp, and you local smtp?
D, Check the SMTP server logs, if you are even receiving the request.
D1, if you are receiving, check which error is causing the timneout, this will likely be in the log.
D2, Start from A, There is something wrong with your connection to the SMTP server.
I am trying to make a Windows Form that sends an email when the user clicks a button, but every time I try, an exception is being raised: Failure sending mail. What is wrong with my code?
private void button1_Click(object sender, EventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential =
new NetworkCredential("username", "password");
MailMessage message = new MailMessage();
MailAddress fromAddress = new MailAddress("myemailadress#gmail.com");
smtpClient.Host = "smpt.gmail.com";
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
message.From = fromAddress;
message.Subject = "your subject";
//Set IsBodyHtml to true means you can send HTML email.
message.IsBodyHtml = true;
message.Body = "<h1>your message body</h1>";
message.To.Add("towhomisend#yahoo.com");
try
{
smtpClient.Send(message);
}
catch (Exception ex)
{
//Error, could not send the message
MessageBox.Show(ex.Message);
}
}
use "smtp.gmail.com" instead of "smpt.gmail.com"
1) Check whether SMTP settings are correct and server is configured correctly (Host & Port Settings)
2)Check whether credentials(user name and password) are correct
3)Check whether firewall is blocking the request
4).Check port 587 If it is blocked in firewall
Port 587:
This is the default mail submission port. When a mail client or server is submitting an email to be routed by a proper mail server, it should always use this port.
The 'smtpClient.Host = "smpt.gmail.com";' part is incorrect.
Change "smpt.gmail.com" to "smtp.gmail.com"
"S M T P" - not - "S M P T"
use "smtp.gmail.com" instead of "smpt.gmail.com"
That aside
Confirm one more thing, You have to enable email from other program in your gmail.
When you try to send once, you will get a notification in you email ID.
You have to enable it there.
I'm rather new to SMTP and IIS settings but according to the documentation on I've read the web this should be working.
What I'm trying to achieve:
To send an email from the server to a users email using an existing SMTP Relay Server.
What I have done:
In my IIS, for my site (ASP.NET), I have configured the SMTP E-mail.
I have entered:
A random E-mail address (it doesn't have to be an existing, right?)
A SMTP Server IP (in this case an IP to an external SMTP Relay Server)
A port number (25).
Autentication Settings to "Not required".
My method for sending an email looks like this:
public static void SendEmail()
{
var message = new MailMessage()
{
Subject = "Heading",
Body = "Body",
message.From = new MailAddress("test#test.com");
message.To.Add("A valid email address"); //My own email address
}
var smtpClient = new SmtpClient("SMTP-Relay-Server-IP", 25); //Same IP as the one in SMTP E-mail configuration in IIS for the site.
smtpClient.Send(message);
}
}
Facts/questions:
Is this correct? Is it correct to also put the Relay Server IP and Port number in the code as parameters in the new SmtpClient?
I don't get an error but I don't receive an email. (I am 100% sure that the "to-email" is correct.
What can be the reason for this not working? What am I missing or misunderstanding?
Wrap your smtpClient.Send(message); in a try/catch block and log any exceptions that are thrown.
A random E-mail address (it doesn't have to be an existing, right?)
That depends on your SMTP provider and configuration.
Without more information on your SMTP provider or an error message I doubt there's anything we can do for you.
MailMessage mail = new MailMessage("sendTo", "from");
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new NetworkCredential("user", "pass");
smtp.Port = 25;
smtp.EnableSsl = true;
smtp.Host = "smtp.gmail.com";
mail.Body = "this my message";
smtp.Send(mail);
should be set out like this
Can we use gmail account to send email in asp.net website from *localhost * (local machine) ? I am trying but badly unsuccessful. It works fine on hosting but donot work on my machine.
I have windows server 2003 on my machine, I have added port 587 and 465 in firewall in exceptions. In my gmail account I also have enabled POP and IMAP. Some people suggest to use port 465 and others say port 587 should be used. I tried both and below was my result:
Using port 465 it take time and finally give message that the opration has timed out. falure
Using port 587 it dont take time, show message "failuer sending email" with an inner expection "No connection could be made because the target machine actively refused it 72.14.213.109:587"
Below is my code, please guide me where I am wrong or what I should do.
thanks
public static bool SendMail(string gMailAccount, string password, string to, string subject, string message)
{
try
{
NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
MailMessage msg = new MailMessage();
msg.From = new MailAddress(gMailAccount);
msg.To.Add(new MailAddress(to));
msg.Subject = subject;
msg.Body = message;
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = loginInfo;
client.Port = 587;
client.Send(msg);
return true;
}
catch (Exception e)
{
return false;
}
}
I use smtp.yandex.com. May be need change settings in your gmail account.
Try this firs: add:
client.DeliveryMethod = SmtpDeliveryMethod.Network;
If that does not help, your mailaddress might not be complete, use
var fromAddress = new MailAddress("from#gmail.com", "From Name");
and in the credentials use
Credentials = new NetworkCredential(fromAddress.Address, ....
Hope that helps
This SmtpClient has always worked for me:
new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
UseDefaultCredentials = false,
Credentials = new NetworkCredential("noreply#my_domain.com", "password")
};
And it matches yours.
Have you been able to contact smtp.gmail.com on port 587 through any other app? Telnet on that port maybe? Am thinking it's probably a network issue, although you did state that your firewall was wide open it's not the only hop between you and google.
I am trying to create a web application which upon entering your email address and message , sends an email with this information from the email address.
I used this:
try
{
NetworkCredential login = new NetworkCredential("your_____#gmail.com", "password");
System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();
email.To.Add(new MailAddress("my____email#gmail.com"));
email.From = new MailAddress("your_____#gmail.com");
email.Subject = "Question";
email.Body = question;
SmtpClient client = new SmtpClient("smtp.gmail.com");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = login;
client.Send(email);
}
catch
{
}
But its giving me an SMTP error.
"Service not available, closing
transmission channel. The server
response was: Cannot connect to SMTP
server 209.85.129.111
(209.85.129.111:25), connect error
10051" System.Exception
{System.Net.Mail.SmtpException}
To send through your gmail account, you need to connect to port 587:
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
You do not need to specify port 587 - the code works without it. I have successfully sent and received e-mail using:
SmtpClient client = new SmtpClient("smtp.gmail.com");
If you look at the error closely, it says "Cannot connect to SMTP server" and error 10051 means the network is unreachable. Do you have a firewall blocking port 587?
Gmail uses port 465 and the erros show port 25
try using 465 port
http://mail.google.com/support/bin/answer.py?answer=76147