0% found this document useful (0 votes)
113 views2 pages

Untitled

This Java class defines methods for sending different types of emails from Apex including plain text, HTML, and attachments. It also includes methods for sending emails using email templates and mass emails. The methods set the necessary email fields like recipients, subject, body and attachments before calling the sendEmail method to deliver the messages.

Uploaded by

R P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
113 views2 pages

Untitled

This Java class defines methods for sending different types of emails from Apex including plain text, HTML, and attachments. It also includes methods for sending emails using email templates and mass emails. The methods set the necessary email fields like recipients, subject, body and attachments before calling the sendEmail method to deliver the messages.

Uploaded by

R P
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

public class OutboundExample {

public Messaging.SingleEmailMessage email1 ;


String[] toadd ;
String[] tocc;
string subject;
public OutboundExample(){
email1=new Messaging.SingleEmailMessage();
toadd=new String[]{'[email protected]'};
tocc=new String[]{'[email protected]'};
}
public void plaintTextBody(){
email1.setToAddresses(toadd);
email1.setCcAddresses(tocc);
email1.setSubject('PlainText Body');
email1.setPlainTextBody('This is a text body');
Messaging.Email[] emails=new Messaging.Email[]{email1};
Messaging.sendEMail(emails);
}
public void htmlBody(){
email1.setToAddresses(toadd);
email1.setCcAddresses(tocc);
email1.setSubject('PlainText Body');
email1.setHtmlBody('<h3> Hai Satish</h3><font style="color:blue">This is
test mail</font>');
Messaging.Email[] emails=new Messaging.Email[]{email1};
Messaging.sendEMail(emails);
}
public void sendAttachments(){
Contact c=[select id,Email from Contact where phone='9988'];
String[] toAdd=new String[]{c.email};
email1.setToAddresses(toAdd);
email1.setCcAddresses(tocc);
email1.setSubject('PlainText Body');
email1.setHtmlBody('<h3> Hai Satish</h3><font style="color:blue">This is
test mail</font>');
PageReference p=Page.page1;
Blob body=P.getContentAsPDF();
Messaging.EmailFileAttachment attach=new Messaging.EmailFileAttachment();
attach.setBody(body);
attach.setFileName('Jan-Feb-Bill.pdf');
Messaging.EmailFileAttachment[] attachments=new
Messaging.EmailFileAttachment[]{attach};
email1.setFileAttachments(attachments);
Messaging.Email[] emails=new Messaging.Email[]{email1};
Messaging.sendEMail(emails);
/* Creating Attachment with with email attachment
Attachment at=new Attachment();
at.ParentId=c.id;
at.body=body;
at.Name='Jan-feb-Bill';
insert at;
*/
}
public void sendTemplate(){
EmailTemplate et=[select id from EmailTemplate where name='Test'];
email1.setTemplateId(et.id);
Contact c=[select id from Contact where phone='9988'];
email1.setTargetObjectId(c.id);
Payment__c p=[select id from Payment__c limit 1];
email1.setWhatId(p.id);
Messaging.Email[] emails=new Messaging.Email[]{email1};
Messaging.sendEMail(emails);
}
public void massEmail(){
Messaging.MassEmailMessage email1=new Messaging.MassEmailMessage();
EmailTemplate et=[select id from EmailTemplate where name='Test'];
email1.setTemplateId(et.id);
Contact c=[select id,Email from Contact where phone='9988'];
email1.setTargetObjectIds(new Id[]{c.id});
Messaging.Email[] emails=new Messaging.Email[]{email1};
Messaging.sendEMail(emails);
}

You might also like