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
gustavogustavo 

Outbound E-mail

I'm starting working with e-mails through Force.com.

Following is the code I'm running. The strange issue is that the success to send an e-mail depends on the text.

First I tried to send only a message written in the body1 variable without success. Only adding an extra character I succeed to send the e-mail.

 

Didn't succeed
String body1='Eureka';
mail.setPlainTextBody( body1);
Succeed
String body1='Eureka';
mail.setPlainTextBody('1'+ body1);

 

 

 

 

// Create a new single email message object
// that will send out a single email to the addresses in the To, CC & BCC list.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
// Strings to hold the email addresses to which you are sending the email.
String[] toAddresses = new String[] {'gustavopipman@hotmail.com'};
//String[] ccAddresses = new String[] {'smith@gmail.com'};
// Assign the addresses for the To and CC lists to the mail object.
mail.setToAddresses(toAddresses);
//mail.setCcAddresses(ccAddresses);
// Specify the address used when the recipients reply to the email.
mail.setReplyTo('gustavopipman@hotmail.com');
// Specify the name used as the display name.
mail.setSenderDisplayName('Gustavo Tests');
// Specify the subject line for your email address.
mail.setSubject('E-mail test 12');
// Set to True if you want to BCC yourself on the email.
mail.setBccSender(false);
// Optionally append the salesforce.com email signature to the email.
// The email address of the user executing the Apex Code will be used.
mail.setUseSignature(false);
// Specify the text content of the email.
String body1='Eureka';
mail.setPlainTextBody('1'+ body1);
//mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created<p>'+
//' View case <a href=https://na1.salesforce.com/'+case.Id+'>click here</a>');
// Send the email you have created.
Messaging.sendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
system.debug(r[0].isSuccess());

// Create a new single email message object// that will send out a single email to the addresses in the To, CC & BCC list.Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();// Strings to hold the email addresses to which you are sending the email.String[] toAddresses = new String[] {'gustavopipman@hotmail.com'};//String[] ccAddresses = new String[] {'smith@gmail.com'};// Assign the addresses for the To and CC lists to the mail object.mail.setToAddresses(toAddresses);//mail.setCcAddresses(ccAddresses);// Specify the address used when the recipients reply to the email.mail.setReplyTo('gustavopipman@hotmail.com');// Specify the name used as the display name.mail.setSenderDisplayName('Gustavo Tests');// Specify the subject line for your email address.mail.setSubject('E-mail test 12');// Set to True if you want to BCC yourself on the email.mail.setBccSender(false);// Optionally append the salesforce.com email signature to the email.// The email address of the user executing the Apex Code will be used.mail.setUseSignature(false);// Specify the text content of the email.String body1='eka';String body2='Eur';mail.setPlainTextBody(body2+ body1);//mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been created<p>'+//' View case <a href=https://na1.salesforce.com/'+case.Id+'>click here</a>');// Send the email you have created.Messaging.sendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });system.debug(r[0].isSuccess());

 

Pradeep_NavatarPradeep_Navatar

I have tried as mentioned below and it worked fine at my end :

 

String body1='Eureka';

mail.setPlainTextBody(body1);