can anyone pls tell me the solution this is the error
--sendanemail: execution of BeforeInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Email address is invalid: test: [toAddresses, test]: Trigger.sendanemail: line 33, column 1
I'm new in trigger I did this trigger for contact so I copied it for opportunity but unable to understand it for opportunity
trigger sendanemail on Opportunity(before insert,before update) {
List<Messaging.SingleEmailMessage> mails =
new List<Messaging.SingleEmailMessage>();
for (Opportunity opp: Trigger.new) {
if (opp.Name!= null && opp.StageName== 'Closed Won') {
Messaging.SingleEmailMessage mail =
new Messaging.SingleEmailMessage();
List<String> sendTo = new List<String>();
sendTo.add(opp.Name);
mail.setToAddresses(sendTo);
mail.setReplyTo('[email protected]');
mail.setSenderDisplayName('Official Bank of Nigeria');
List<String> ccTo = new List<String>();
ccTo.add('[email protected]');
mail.setCcAddresses(ccTo);
mail.setSubject('URGENT BUSINESS PROPOSAL');
String body = 'Dear ' + opp.Name+ ', ';
body += 'I confess this will come as a surprise to you.';
body += 'I am John Alliston CEO of the Bank of Nigeria.';
mail.setHtmlBody(body);
mails.add(mail);
}
}
Messaging.sendEmail(mails);
}