//simple email
mailmessage mail = new mailmessage();
mail.to = “me@mycompany.com”;
mail.from = “you@yourcompany.com”;
mail.subject = “this is a test email.”;
mail.body = “this is my test email body”;
smtpmail.smtpserver = “localhost”; //your real server goes here
smtpmail.send( mail );
//simple html email
mailmessage mail = new mailmessage();
mail.to = “me@mycompany.com”;
mail.from = “you@yourcompany.com”;
mail.subject = “this is a test email.”;
mail.bodyformat = mailformat.html;
mail.body = “this is my test email body.<br><b>this part is in bold</b>”;
smtpmail.smtpserver = “localhost”; //your real server goes here
smtpmail.send( mail );
//email with attachments
mailmessage mail = new mailmessage();
mail.to = “me@mycompany.com”;
mail.from = “you@yourcompany.com”;
mail.subject = “this is a test email.”;
mail.body = “this is my test email body.”;
mailattachment attachment = new mailattachment( server.mappath( “test.txt” ) ); //create the attachment
mail.attachments.add( attachment ); //add the attachment
smtpmail.smtpserver = “localhost”; //your real server goes here
smtpmail.send( mail );
//change the to address to a friendly name
mail.from = “\”john smith\” <you@yourcompany.com>”;
//multiple recipients
mail.to = “me@mycompany.com;him@hiscompany.com;her@hercompany.com”;
