// Collection of code snippets by Arne Vajhøj // posted to eksperten.dk, usenet and other places (2002-now) using System; using System.IO; using System.Net; using System.Net.Sockets; public class EMailDemo { public static void EMail(string mailserver, string to, string from, string subj, string body) { string ownhost = Dns.GetHostName(); TcpClient client = new TcpClient(mailserver, 25); StreamWriter wrt = new StreamWriter(client.GetStream()); wrt.WriteLine("HELO " + ownhost); wrt.WriteLine("MAIL FROM: <" + from + ">"); wrt.WriteLine("RCPT TO: <" + to + ">"); wrt.WriteLine("DATA"); wrt.WriteLine("Return-Path: <" + from + ">"); wrt.WriteLine("From: " + from); wrt.WriteLine("To: " + to); wrt.WriteLine("Subject: " + subj); wrt.WriteLine(); wrt.WriteLine(body); wrt.WriteLine("."); wrt.WriteLine("QUIT"); wrt.Flush(); wrt.Close(); client.Close(); } public static void Main(string[] args) { EMail("192.168.1.10", "arne@arne", "arne@arne", "Test", "Dette er en test\r\nEn anden linie"); } }