title: SMTP relay - send email from console application
body: <p>Is it possible to send email from a server that uses smtp-relay through a .net application.</p>
  
  <p>I'm using app.config to get the actual values ex server IP, and the fromadress that the email should use.</p>
  
  <p>According to the IT-technician the username and password to authorize should not be needed because it uses smtp-relay. The computer that are going to send the email is on the smtp-servers list of valid computers.</p>
  
  <p>Can this actually work, don't I need to specify the username/pwd?</p>
  
  <pre><code>try
  {
      MailMessage mail = new MailMessage();
      SmtpClient SmtpServer = new SmtpClient(_smtpserver);
      mail.From = new MailAddress(_fromAdress);
      mail.To.Add(_toAdress);
      mail.Subject = _subject;
      mail.Body = _body;
      mail.Priority = MailPriority.High;
      SmtpServer.Port = Convert.ToInt32(_port);
      SmtpServer.Credentials = new System.Net.NetworkCredential(_authUsername, _authPassword);
      SmtpServer.EnableSsl = true;
      SmtpServer.Send(mail);
  }
  catch (Exception ex)
  {
      Console.WriteLine(ex.ToString());
  }
  </code></pre>