You need to sign in to do that
Don't have an account?
venkateshyadav1243
send mass email with comma separated
Hi
i have one custom button to send email. its working fine.
I have one email field.
what i have to do is in my email field if i give like this
test@gmail.com,test1@gmail.com,test2@gmail.com,test3@gmail.com
i need to send email to all emails i provided in the email field
Is this possibel in salesforce
can any one tell me how can i achive this
Regards
venkatesh.
Make Email field as textArea field it will work.......
Hi,
you can look into this code
email can contain more than 1 {1@gmail.com, 2@gmail.com, .....};
mail.setToAddresses(new String[] {email});
mail.setSubject(Subject);
mail.setHtmlBody(Body);
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
mails.add(mail);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for(User portalUser :lstPortalUser)
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
string body = 'Hi '+ portalUser.LastName;
mail.setSubject('Test Subject');
mail.setTargetObjectId(portalUser.Id);
mail.setSaveAsActivity(false);
mail.setHtmlBody(body);
mails.add(mail);
}
Messaging.sendEmail(mails);
link http://devendranatani.blogspot.in/
Hi Venkat,
In your email filed if u given like this :test@gmail.com,test1@gmail.com,test2@gmail.com,tes
t3@gmail.com
When ever u saving the record You will get error like this:Error: Invalid Email Address.
It will take only one mail id like this:test@gmail.com..It will not accept all emails in single record...
Please try it once..
Thanks,
Cool Sfdc
Hi...
I have one example.. I hope this will helps you...
public void doSendEmail() {
try {
EmailFileAttachment efa = new EmailFileAttachment();
byte[] fileBody = new byte[1000000];
efa.setBody(fileBody);
efa.setFileName("attachment");
SingleEmailMessage message = new SingleEmailMessage();
message.setBccAddresses(new String[] {
"someone@gmail.com"
});
message.setCcAddresses(new String[] {
"person1@gmail.com", "person2@gmail.com"
});
message.setBccSender(true);
message.setEmailPriority(EmailPriority.High);
message.setReplyTo("person1@gmail.com");
message.setSaveAsActivity(false);
message.setSubject("This is how you use the " + "sendEmail method.");
// We can also just use an id for an implicit to address
GetUserInfoResult guir = connection.getUserInfo();
message.setTargetObjectId(guir.getUserId());
message.setUseSignature(true);
message.setPlainTextBody("This is the humongous body "
+ "of the message.");
EmailFileAttachment[] efas = { efa };
message.setFileAttachments(efas);
message.setToAddresses(new String[] { "person3@gmail.com","person4@gmail.com" });
SingleEmailMessage[] messages = { message };
SendEmailResult[] results = connection.sendEmail(messages);
if (results[0].isSuccess()) {
System.out.println("The email was sent successfully.");
} else {
System.out.println("The email failed to send: "
+ results[0].getErrors()[0].getMessage());
}
} catch (ConnectionException ce) {
ce.printStackTrace();
}
}
Thanks,
Cool Sfdc
field1 with text area type (Email1
field2 with formula field with formula as Email & ", " & Email1__c
and assigned the Email2 field value in code as mail.setToAddresses(new String[] {email2__c});
Check it and tel if any pbm means.....
Hi Thanks for all giving replay to my question
I implemented possible ways,am getting the error invalid email address,if i provide more than one email in my text field
this my code please tell me where am missing.
global class SendOfferEmail
{
public static blob b;
WebService static string OfferSendEmail(string id)
{
try
{
Quote qt=[Select q.Internal_Email_User_Id__c,q.Revision__c from Quote q where q.id=:id];
PageReference pdf =new PageReference('/apex/New_Offer?scontrolCaching=1&id='+Id);
pdf.setRedirect(true);
if(Test.isRunningTest() == false){
b = pdf.getContent();
}
//--------create a mail object to send a single email.--------
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new string[] {qt.Internal_Email_User_Id__c}); // Internal_Email_User_Id__c text fied
mail.setBccAddresses(new String[] {'sf@xxxxx.com'});
mail.setBccSender(true);
mail.setSenderDisplayName('xxxxxx');
mail.setSubject('Offer');
//------------- Create the email attachment-----------------
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('Offer.pdf');
efa.setBody(b);
//-----------------------------------------------------------
mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
mail.setHtmlBody('Hi Sir/Madam, Please find the offer attached to this mail.');
//------------------------Attach sales order to a contract--------------------
Attachment formAttach = new Attachment();
formAttach.Name = 'Offer-Rev-'+qt.Revision__c+'.pdf';
formAttach.body = b;
formAttach.ContentType='application/pdf';
formAttach.parentId =id;
if (!Test.isRunningTest())
{
insert formAttach;
}
//send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );
return 'Offer has been sent';
}
catch(exception ex)
{
string ex1=string.valueof(ex);
return ex1;
}
}
}
Regards
venkatesh
hello,
global class SendOfferEmail
{
public static blob b;
WebService static string OfferSendEmail(string id)
{
try
{
Quote qt=[Select q.Internal_Email_User_Id__c,q.Revision__c from Quote q where q.id=:id];
PageReference pdf =new PageReference('/apex/New_Offer?scontrolCaching=1&id='+Id);
pdf.setRedirect(true);
if(Test.isRunningTest() == false){
b = pdf.getContent();
}
//--------create a mail object to send a single email.--------
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new string[] {qt.Internal_Email_User_Id__c}); // Internal_Email_User_Id__c text fied
// it is an User id not email id and if you would like to send an email to Internal User you shouldn't use setToAddress bcz it will cound the againest to the email limitiations you can see more detials
http://www.cloudjedi.com/blog/salesforce/single-email-limit/
you can use mail.setTargetobjectId(new string[] {qt.Internal_Email_User_Id__c);// it will send an email to respective user
mail.setBccAddresses(new String[] {'sf@xxxxx.com'});
mail.setBccSender(true);
mail.setSenderDisplayName('xxxxxx');
mail.setSubject('Offer');
//------------- Create the email attachment-----------------
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('Offer.pdf');
efa.setBody(b);
//-----------------------------------------------------------
mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
mail.setHtmlBody('Hi Sir/Madam, Please find the offer attached to this mail.');
//------------------------Attach sales order to a contract--------------------
Attachment formAttach = new Attachment();
formAttach.Name = 'Offer-Rev-'+qt.Revision__c+'.pdf';
formAttach.body = b;
formAttach.ContentType='application/pdf';
formAttach.parentId =id;
if (!Test.isRunningTest())
{
insert formAttach;
}
//send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );
return 'Offer has been sent';
}
catch(exception ex)
{
string ex1=string.valueof(ex);
return ex1;
}
}
}