I'm trying to send email using the following code. It is hosted in godaddy.
MailMessage mail = new MailMessage("[email protected]", "[email protected]");
MailMessage mail = new MailMessage("[email protected]", "[email protected]");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.gmail.com";
mail.Subject = "Test email";
string body;
using (var sr = new StreamReader(HttpContext.Current.Server.MapPath("~/App_Data/Template/") + "Email.html"))
{
body = sr.ReadToEnd();
}
string messageBody = string.Format(body, name, expDate);
mail.Body = messageBody;
Attachment doc = new Attachment(HttpContext.Current.Server.MapPath("~/App_Data/class_3b.pdf"));
mail.Attachments.Add(doc);
client.Send(mail);
But I'm getting error:
{System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.130.109:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)}