I am trying to send a mail the form posts, but when the form posts it tries to send the mail and then times out. the code that is timing out is this:
MailMessage mail = new MailMessage();
mail.From = new MailAddress("someone#example.com");
mail.To.Add("someoneElse#example.com");
SmtpClient smtp = new SmtpClient();
smtp.Port = 465;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Host = "smtp.gmail.com";
mail.Subject = "Hello";
mail.Body = "World!";
smtp.Send(mail);
This is almost certainly an issue with your client setup.
If you're using port 465, you're required to use SSL -
See here https://support.google.com/a/answer/176600?hl=en
In your current client setup this is omitted.
Also, I think you're missing your credentials.
Try changing your client to
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 587;
client.EnableSsl = true; //ssl is required
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("your-email#gmail.com", "YourPassword");
client.Timeout = 20000; //increase the timeout
As mentioned in the comments, you may also need to allow "less secure apps" access to your account -
Info here http://support.google.com/accounts/answer/6010255
Related
I am using C#. I have a method in which the SMTP client is configured and an email is sent:
MailMessage mail = new MailMessage("myEmail#myDomain.com", "otherEmail#google.com");
mail.CC.Add("otherEmailInMyDomain#myDomain.com");
mail.Subject = "Normal Subject";
mailMessage.Body = "Normal Body";
SmtpClient client = new SmtpClient();
client.EnableSsl = true;
client.Port = 587;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = credentials;
client.Host = "smtp.office365.com";
client.Send(mailMessage);
The email is being received by the otherEmail#google.com (to which it is being sent directly), but is not being received by the otherEmailInMyDomain#myDomain.com.
This error only happens in the server, whenever i try this code in my machine, it works perfectly.
I want to send mail. I have following code which was working perfectly. But since few days, I am getting following error.
Error: Service not available, closing transmission channel. The server response was: Server busy, closing transmission channel. Try
again later
Code:
try
{
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
using (MailMessage mm = new MailMessage("xxx#gmail.com", "yyy#gmail.com"))
{
mm.Subject = "Registration Successfully";
mm.Body = "You are registered successfully. Welcome.";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("xxx#gmail.com", "password");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
}
}
catch (Exception)
{
throw;
}
I have read following blogs and tried but didnt work.
1- Email alerts -while sending mail to multiple user 1 by 1 getting error as server busy
2- Send Bulk Email From Yahoo and Hotmail Using ASP.Net
don't use SMTP smtp.gmail.com some times create problem
best solution
mm.Subject = "Registration Successfully";
mm.Body = "You are registered successfully. Welcome.";
mm.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = "domainname.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential("demo#domainname.com", "password");
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm);
SmtpClient client = new SmtpClient();
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.Timeout = 10000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("*********#gmail.com", "***********");
MailMessage mm = new MailMessage("*********#gmail.com", "******#gmail.com", "delivery.", "tttt");
mm.BodyEncoding = UTF8Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
Attachment fMailAttachment;
fMailAttachment = new Attachment(FilePath);
mm.Attachments.Add(fMailAttachment);
client.Send(mm);
mm.Attachments.Dispose();
I am trying to send an email using this code. It works well but only when I am logging in my mail and let it opened, when I close mail it does not send any mails.
what is the problem with that code ?
It works well after I edited
client.Timeout = 10000;
To
client.Timeout = 100000;
I checked other questions, and i was able to resolve some errors in my code, but smtp.Credentials = nc; , where nc is my Network credentials, is throwing an exception, Request action aborted on MFE proxy, SMTP server is not available.
Please, any help would be appreciated. Below, is my code :
MailMessage msg = new MailMessage();
msg.From = new MailAddress("fromemail");
msg.To.Add("toemail");
msg.Subject = "Contact Us";
msg.Body = cname.Text + "sent me this message" + cmessage.Text + "with this email, " + email.Text;
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
smtp.EnableSsl = false;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
NetworkCredential nc = new NetworkCredential();
nc.UserName = "fromemail";
nc.Password = "fromemailpwd";
smtp.Credentials = nc;
smtp.Port = 587;
smtp.Send(msg);
sPanel.Visible = true;
lblSuccess.Text = "Success! Thanks for contacting us, we will get back to you soon.";
I changed the smtp.Credentials = nc to smtp.Credentials = new NetworkCredentials("fromemail", "fromemailpwd");
Now, it is this line, smtp.Send(msg), that is throwing the exception.
I wasn't able to get the same error message that you saw, but check out this answer : Request action aborted on MFE proxy, SMTP server is not available
However, I do know that Gmail requires EnableSSL = True
I have some code that can only work with my SMTP host domains but not others. It seems to send, but it doesn't actually send anything and it also doesn't throw any exceptions.
SmtpClient mailClient = new SmtpClient();
mailClient.UseDefaultCredentials = false;
mailClient.Port = 587;
mailClient.EnableSsl = false;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.Host = "mail.smtpserver.com";
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("mail#smtpserver.com", "password");
mailClient.Credentials = cred;
MailMessage message = new MailMessage();
message.From = new MailAddress("mail#smtpserver.com");
message.To.Add("mail#remotedomain.com");
message.Subject = "Subject";
message.Body = "Body";
mailClient.Timeout = 200000;
mailClient.Send(message);
I think the problem is not checking NetworkCredential...
I would suggest you to try to send a testing mail with the "other" smtp server using telnet to make sure it works.
your smtp port is not the default one so maybe it is blocked by your firewall.
Generally, if you're using port 587 then that is SSL secured SMTP - so you need to change your code so that uses it when establishing the connection:
mailClient.EnableSsl = true;