+ Start a Discussion

Email to Notes & Attachement

Please Reply to this requirement urgently with code.


One Account present in salesforce (Flipcart application) and  that acclunt email id =abc@gmail.com.


If I send email from particular email id (abc@gmail.com) to sales@flipcart.com, automaticllay one record with Email subject should be stored in Notes & Attachment of particular account.


Please help me


Create detail pagecustom button account named as send email

and select execute Javascript and onclick kjava script as 




vf page :


<apex:page controller="sendEmailFromAccount" showHeader="False" sidebar="false">
  <apex:form >
        <apex:pageBlock >
         <apex:outputLabel >To:</apex:outputLabel> <apex:inputText Value="{!toAddr}"/> <br/>
          <apex:outputLabel >Subject:</apex:outputLabel> <apex:inputTextarea Value="{!toSub}"/><br/>
          <apex:outputLabel >Body:</apex:outputLabel> <apex:inputText Value="{!toBody}"/>
          <apex:pageBlockButtons >
          <apex:commandButton value="send" action="{!sendEmail}"/>


Apex controller:


public with sharing class sendEmailFromAccount {

    public String toBody { get; set; }

    public String toSub { get; set; }

    public String toAddr { get; set; }
    public  String accId  {get;set;}
    public List<Attachment> attList = new List<Attachment>();
    public Account accDetails{get;set;}

 public sendEmailFromAccount(){
 accId  = Apexpages.currentpage().getParameters().get('accid');
 accDetails = [Select id, email__c from Account where id=:accId];

    public PageReference sendEmail() {
      Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
      String[] toAddresses = new string[]{toAddr};
       email.setSubject( toSub );
       email.setToAddresses( toAddresses );
       email.setPlainTextBody( toBody );
       Messaging.SendEmailResult [] srlist =  Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});   
       for(Messaging.SendEmailResult sr: srlist) {
            Attachment attOne = new Attachment();
            attOne .body =Blob.valueOf(toBody);
            attOne.parentId = accId;
            insert attList;
        catch(Exception ex){
        return null;




if you want to send multiple emails, use mass email messages instead of single email message service.


Thanks for the Reply....


Actually my requirement was totally different. I want to capture as an attachment if user send email from his mail id to flipcart.com....


This is same as Email to case. I want that kind of code