I am trying to create a small desktop app that sends out e-mails to people in the office (all internal). My application would run on a PC that is also on the network and the user will have outlook running for his own e-mails.
I’m looking at several examples where you need the SmtpClient and it needs to equal a host. Is there a way that I can just set it to use the local machine?
MailMessage mailObj = new MailMessage("admin@network.com",
reader["recipientAddress"].ToString(), "Subject", "Body");
SmtpClient SMTPServer = new SmtpClient("127.0.0.1");
SMTPServer.Send(mailObj);
I read that 127.0.0.1 is the local machine. Would this work, or is there a different way of going about this?
Also would my messages go out if it sent a message to an external email?
You have to install a SMTP server on your localhost to be able to send mail.
Outlook only receives e-mails through POP3 or IMAP, etc.
edit:
i.e. you need
Your company mail server should normally do both.
edit2:
You might be able to cheat and use
SMTPClientto deliver the mail to the receiver’s mailbox server directly though.Try resolving for the MX record (see How to get mx records for a dns name with System.Net.DNS?) and create a
SMTPClientdirectly to the best MX server returned.If Microsoft implemented enough of the SMTP specification and your host is not treated as sending spam, the mail should go through.