Controller:
----------
public class SendEmailSample
{
public String emailTo {get; set;}
public String emailBody {get; set;}
public String response {get; set;}
String[] Users = new String[]{};
//string Users = null;
public string[] getUsers()
{
Return Users;
}
public void setUsers(string[] Users)
{
this.Users=Users;
}
public List<SelectOption> getItems()
{
List<SelectOption> options = new List<SelectOption>();
List<User> UserVar = [Select u.Email, u.Name from User u];
for(User U : UserVar)
{
options.add(new SelectOption(U.Email,U.Name ));
}
return options;
}
public PageReference sendEmail(){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(Users);
mail.setReplyTo('arjunan@yahoo.com');
mail.setSenderDisplayName('Thylak SOFT');
mail.setSubject('Test Email From Force.com Sites');
mail.setPlainTextBody(emailBody);
try{
Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
if(resultMail[0].isSuccess())
return Page.opptyStep2;
//response = 'ok sent!';
else{
response = resultMail[0].getErrors().get(0).getMessage();
}
}catch(System.EmailException ex){
response = ex.getMessage();
}
return null;
}
public PageReference test()
{
return null;
}
}
Page Editor:
------------
<APEX:PAGE controller="SendEmailSample" sidebar="true" standardStylesheets="true" showHeader="true" >
<APEX:FORM >
<APEX:PANELGRID columns="2" border="0" cellspacing="2">
<APEX:OUTPUTTEXT value="Email To :"></APEX:OUTPUTTEXT>
<apex:selectList size="5" multiselect="true" value="{!Users}" style="width:400px">
<apex:selectOptions value="{!items}" ></apex:selectOptions>
</apex:selectList>
<APEX:OUTPUTTEXT value="Email Body :"></APEX:OUTPUTTEXT>
<APEX:INPUTTEXTAREA style="WIDTH: 400px; HEIGHT: 100px" value="{!emailBody}"></APEX:INPUTTEXTAREA>
<APEX:COMMANDBUTTON value="Send" rerender="statusMail" action="{!sendEmail}"></APEX:COMMANDBUTTON>
<APEX:OUTPUTPANEL id="statusMail" layout="block">
<STRONG><APEX:OUTPUTTEXT value="{!response}"></APEX:OUTPUTTEXT></STRONG>
</APEX:OUTPUTPANEL>
</APEX:PANELGRID>
</APEX:FORM>
<apex:outputPanel id="out">
<apex:actionstatus id="status" startText="Loading...">
<apex:facet name="stop">
<apex:outputPanel >
<!--<p>You have selected:</p>-->
<apex:dataList value="{!Users}" var="c">a:{!c}</apex:dataList>
</apex:outputPanel>
</apex:facet>
</apex:actionstatus>
</apex:outputPanel>
</APEX:PAGE>
No comments:
Post a Comment
Share your Comments .............