Reputation: 6147
I'm trying to send and email from a C# application running on the desktop. Does anyone see any particular reason why this would error and time out, as a result never sending the email. I've looked around online and haven't been able to find a solution which actually works when doing this.
I do however had a php mail which runs directly off the godaddy server which sends emails. So i know the server isn't the problem. The php version doesn't require a password.
Here is the code.
SmtpClient ss = new SmtpClient();
try
{
ss.Host = "relay-hosting.secureserver.net";
ss.Port = 25;
ss.Timeout = 10000;
ss.DeliveryMethod = SmtpDeliveryMethod.Network;
ss.UseDefaultCredentials = false;
ss.Credentials = new NetworkCredential("[email protected]", "####");
MailMessage mailMsg = new MailMessage("[email protected]", "[email protected]", "testing email", "my body");
mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
ss.Send(mailMsg);
Console.WriteLine("Sent email");
Console.ReadKey();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadKey();
}
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll Exception thrown: 'System.Net.WebException' in System.dll Exception thrown: 'System.Net.WebException' in System.dll Exception thrown: 'System.Net.WebException' in System.dll Exception thrown: 'System.Net.Mail.SmtpException' in System.dll Exception thrown: 'System.InvalidOperationException' in mscorlib.dll
Upvotes: 0
Views: 1492
Reputation: 18843
create a method like this to test either from your local mailhost then try it with godaddy
public static void SendEmail(string subject, string body)
{
using (var client = new SmtpClient(yourEmailHost, 25)) //"relay-hosting.secureserver.net"
using (var message = new MailMessage()
{
From = new MailAddress(utilities.FromEmail),
Subject = subject,
Body = body
})
{
message.To.Add(address);
//client.DeliveryMethod = SmtpDeliveryMethod.Network;
//client.Credentials = new NetworkCredential("nerwork UserName", "Network Password");
client.Send(message);
};
}
Upvotes: 1