I have a requirement for an email program to send SMTP mail without having IIS (and therefore no SMTP service) installed on work stations. I found a nice solution to this at http://www.eggheadcafe.com/articles/20030316.asp. I modified the code to fit my needs and it works. However I have a couple of issues.
One: How do I cause the SMTP server to send out delivery notifications on failure and success This is pretty easy using the DeliveryNotificationOptions of the System.Net.Mail.MailMessage class. But of course I am not using this.
Two: How do I send authentication or system credentials to the SMTP server Again, this is pretty simple using the System.Net.Mail.Message class.
Example code:
IPHostEntry IPhst = Dns.GetHostEntry(SmtpServer); IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25); Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);s.Connect(endPt);
Senddata(s,
string.Format("EHLO {0}\r\n", Dns.GetHostName()));Senddata(s,
string.Format("MAIL From: {0}\r\n", message.From));Senddata(s,
string.Format("RCPT TO: {0}\r\n", strTo));StringBuilder
Header = new StringBuilder();Header.AppendLine(
"From: " + message.From.ToString());Header.Append(
"To: "+strTo); string MsgBody = message.Body;Header.Append(
"Date: ");Header.AppendLine(
DateTime.Now.ToString("ddd, d M y H:m:s z"));Header.AppendLine(
"Subject: " + message.Subject);Header.AppendLine(
"X-Mailer: SMTPDirect v1");Header.AppendLine(
"MIME-Version: 1.0");Header.AppendLine(
"Content-Type: multipart/mixed; boundary=unique-boundary-1");Header.AppendLine();
Header.AppendLine(
"--unique-boundary-1");Header.AppendLine(
"Content-Type: text/html");Header.AppendLine(
"Content-Transfer-Encoding: 7Bit");Header.AppendLine();
Header.AppendLine(MsgBody);
Header.AppendLine(
".");Header.AppendLine();
Header.AppendLine();
Senddata(s, ("DATA\r\n"));
Senddata(s, Header.ToString());
Senddata(s,
"QUIT\r\n");s.Close();
...