function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Complete noviceComplete novice 

Help for writing a custom controller and component for a VF email please

I've just about got my head around amending pre-written VF email templates but now find I need to write a custom controller and component, which means I am seriously out of my depth.

This is what I am trying to achieve:

An email to be sent from an opportunity.  It is sent to the primary opportunity contact and details the opportunity product, plus some fields from the Account record.  I can do this bit.  However I have also been asked to include specific contacts from the Account related contacts list.  

I understand this needs a custom controller and component but I don't understand how to build these.

Can anyone help me please? You would be helping me out of a massive hole!

This is the code I have so far which retuns the opportunity propduct and the Account record fields:

messaging:emailTemplate subject="Renewal." recipientType="Contact" relatedToType="Opportunity"
 replyTo="" >
<messaging:htmlEmailBody >        
        <apex:image id="Email_Header"
height="130" width="600"/>

         <STYLE type="text/css">
                  TH {font-size: 14px; font-face: arial;background: #FFFFFF; border-width: 0;  text-align: center }
               TD  {font-size: 14px; font-face: arial }
           <font face="arial" size="2">
      <p/>  Dear  
    <apex:repeat value="{!RelatedTo.OpportunityContactRoles}" var="ContactRole">
<apex:outputText value=" {!ContactRole.Contact.Name}" rendered="{!AND(ContactRole.isPrimary)}"></apex:outputtext>

        {!RelatedTo.Account.Name}'s membership expires on <apex:outputText value=" {0, date,EEEE d MMMM yyyy}"> <apex:param value="{!relatedTo.Asset_Expires_When__c}"/> </apex:outputtext>.
Our records show the information below about your company:
             <td><b>•   </b> Company Size: {!relatedTo.Account.Number_of_Employees__c} employees</td>
             <td><b>•   </b> Turnover: {!relatedTo.Account.CurrencyIsoCode} {!relatedTo.Account.AnnualRevenue}</td>

<p/>  <apex:repeat var="opp" value="{!relatedTo.OpportunityLineItems}">  
       <td><b>•   </b> Membership type {!}.</td> <br/>

Thanks in advance.