- mail.setToAddress(List<String>)
➡️ 여기서 String은 Address를 뜻함- mail.setSubject('');
- mail.setHtmlBody('');
※ 주의
Address는 list로 setting
List<Messaging.SingleEmailMessage> listMails = new List<Messaging.SingleEmailMessage>();
List<String> listAddress = new List<String>();
for(Contact obj : listContact) {
if(obj.Email != null) {
listAddress.add(obj.Email);
}
}
if(!listAddress.isEmpty()){
for(Contact obj : listContact) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(listAddress);
mail.setSubject('[SFDC] ' + obj.Name + '님 안녕하세요.');
mail.setHtmlBody('<p>배치 클래스 테스트입니다.<p></br><h1>TEST</h1>');
listMails.add(mail);
}
}
- Messaging.sendEmail(List<SingleEmailMessage>);
if(!listMails.isEmpty()){
Messaging.sendEmail(listMails);
}
List<Messaging.SingleEmailMessage> listMails = new List<Messaging.SingleEmailMessage>();
List<String> listAddress = new List<String>();
for(Contact obj : listContact) {
if(obj.Email != null) {
listAddress.add(obj.Email);
}
}
if(!listAddress.isEmpty()){
for(Contact obj : listContact) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(listAddress);
mail.setSubject('[SFDC] ' + obj.Name + '님 안녕하세요.');
mail.setHtmlBody('<p>배치 클래스 테스트입니다.<p></br><h1>TEST</h1>');
listMails.add(mail);
}
if(!listMails.isEmpty()){
Messaging.sendEmail(listMails);
}
}