// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Drawing; using System.Windows.Forms; using System.Web.Mail; namespace MyFormProject { class MainForm : Form { private Label tolabel; private Label subjlabel; private Label msglabel; private TextBox to; private TextBox subj; private TextBox msg; private Button send; public MainForm() { tolabel = new Label(); subjlabel = new Label(); msglabel = new Label(); to = new TextBox(); subj = new TextBox(); msg = new TextBox(); send = new Button(); tolabel.Location = new Point(50, 50); tolabel.Text = "To:"; to.Location = new Point(150, 50); to.Size = new Size(200, 25); subjlabel.Location = new Point(50, 100); subjlabel.Text = "Subj::"; subj.Location = new Point(150, 100); subj.Size = new Size(200, 25); msglabel.Location = new Point(50, 150); msglabel.Text = "Send:"; msg.Location = new Point(150, 150); msg.Size = new Size(200, 100); msg.Multiline = true; send.Location = new Point(150, 300); send.Text = "Send email"; send.Click += new EventHandler(ClickHandler); ClientSize = new Size(400, 350); Controls.Add(tolabel); Controls.Add(to); Controls.Add(subjlabel); Controls.Add(subj); Controls.Add(msglabel); Controls.Add(msg); Controls.Add(send); Text = "Mail Form"; } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } private void ClickHandler(object o, EventArgs e) { SmtpMail.SmtpServer = "192.168.1.10"; SmtpMail.Send("noone@nowhere.dk", to.Text, subj.Text, msg.Text); MessageBox.Show("Mail send"); to.Text = ""; subj.Text = ""; msg.Text = ""; } } }