System.Net.Mail problem
-
Hi, I'm trying to create a function that will automaticly send me the errors of the application using the MailMessage function from the namespace: System.Net.Mail. This is the code I have now but for some reason it aint working. It gives me the following error (sorry it's in dutch): "Postbus niet beschrikbaar. Het serverantwoord is: 5.7.1 Unable to relay for email@company.nl"
try
{
MailMessage message = new MailMessage();message.From = new MailAddress("info@company.nl", "Application AutoEmail", System.Text.Encoding.UTF8); message.To.Add(new MailAddress("email@company.nl")); message.Subject = "Application error"; message.Body = "This is the content..."; message.Priority = MailPriority.Normal; SmtpClient client = new SmtpClient(); client.Host = "localhost"; client.Port = 25; client.Send(message); MessageBox.Show("Your email has succesfully been send.", "Email send");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}What am I doing wrong?
-
Hi, I'm trying to create a function that will automaticly send me the errors of the application using the MailMessage function from the namespace: System.Net.Mail. This is the code I have now but for some reason it aint working. It gives me the following error (sorry it's in dutch): "Postbus niet beschrikbaar. Het serverantwoord is: 5.7.1 Unable to relay for email@company.nl"
try
{
MailMessage message = new MailMessage();message.From = new MailAddress("info@company.nl", "Application AutoEmail", System.Text.Encoding.UTF8); message.To.Add(new MailAddress("email@company.nl")); message.Subject = "Application error"; message.Body = "This is the content..."; message.Priority = MailPriority.Normal; SmtpClient client = new SmtpClient(); client.Host = "localhost"; client.Port = 25; client.Send(message); MessageBox.Show("Your email has succesfully been send.", "Email send");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}What am I doing wrong?
-
Your local SMTP server is not set up correctly.
xacc.ide - now with TabsToSpaces support
IronScheme - 1.0 alpha 3 out nowThank you! I changed "localhost" to "ExchangeServer" (our local mail server) and it worked. But if the application is running on a computer outside our network, the SMTP host will be different. So is there a way to determine the SMTP host address/name of the current computer/user?
-
Thank you! I changed "localhost" to "ExchangeServer" (our local mail server) and it worked. But if the application is running on a computer outside our network, the SMTP host will be different. So is there a way to determine the SMTP host address/name of the current computer/user?
If the Exchange server is internet accessible (a fully qualified domain name), then just use that instead so that if you're deploying outside of your LAN, it can still be reached. If not, then you might need to allow for user configuration to specify the SMTP server name or address.
-
If the Exchange server is internet accessible (a fully qualified domain name), then just use that instead so that if you're deploying outside of your LAN, it can still be reached. If not, then you might need to allow for user configuration to specify the SMTP server name or address.
Ah ok... But it's not possible to get the hostname/address from the SMTP server in C#?