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
adiezadiez 

Send Email problem

Hi all.

I'm experimenting with sending mail from APEX and have a serious problem... It isn't sent. I put the code below, but is the typical code you can find in these forums:

 

public class newController { public String myMessages {get{return this.myMessages;}set;} public newController (){ // 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[] {'myadress@one.com'}; String[] ccAddresses = new String[] {'otheradress@yahoo.es'}; // 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('adiez@proclientia.com'); // Specify the name used as the display name. mail.setSenderDisplayName('Salesforce Support'); // Specify the subject line for your email address. mail.setSubject('New Case Created : '); // Set to True if you want to BCC yourself on the email. mail.setBccSender(true); // 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. mail.setPlainTextBody('Your Case: has been created'); mail.setHtmlBody('Your case:<b> blablabla </b>has been created<p>'+ ' View case <a href=http://www.google.es>click here</a>'); // Send the email you have created. this.myMessages = ''+Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } }

 and my VF page:

 

<apex:page controller="newController"> {!myMessages} </apex:page>

 The result:

 

(Messaging.SendEmailResult[getErrors=();isSuccess=true;])

 

So, why not send the email?

thanks in advance.

adiez

Salesforce Consulting Partner in Spain

www.proclientia.com

 

 

 

 

NaishadhNaishadh

Hi,

 

Try using some different email address. I have tested it using my gmail account. It is working fine for me.

 

 

adiezadiez

Hi Naishadh,

I've tried changing the email address, but it isn't work, could be the problem caused by some parameters in Salesforce? could be this method off in a developer's account?
Thanks
 
adiez

 

Salesforce Consulting Partner in Spain

www.proclientia.com

NaishadhNaishadh
Cross check your profile. Do you have Send Email option enable or not.
adiezadiez
I have checked the options and all options are active. I've tried to do this using a trigger and it worked just fine, so my question is whether it is possible to send mail using only the APEX and VF.
 
My trigger code:

trigger Contact_AU on Contact (after update) { for(Contact contacto : Trigger.new){ Contact aux = Trigger.oldMap.get(contacto.Id); Contact ct = [Select c.Title, c.SystemModstamp, c.Salutation, c.ReportsToId, c.Phone, c.OwnerId, c.OtherStreet, c.OtherState, c.OtherPostalCode, c.OtherPhone, c.OtherCountry, c.OtherCity, c.Name, c.MobilePhone, c.MasterRecordId, c.MailingStreet, c.MailingState, c.MailingPostalCode, c.MailingCountry, c.MailingCity, c.Level__c, c.LeadSource, c.LastName, c.LastModifiedDate, c.LastModifiedById, c.LastCUUpdateDate, c.LastCURequestDate, c.LastActivityDate, c.Languages__c, c.IsDeleted, c.Id, c.HomePhone, c.FirstName, c.Fax, c.EmailBouncedReason, c.EmailBouncedDate, c.Email, c.Description, c.Department, c.CreatedDate, c.CreatedById, c.Birthdate, c.AssistantPhone, c.AssistantName, c.AccountId From Contact c where c.Id = :aux.Id limit 1]; // 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[] {ct.Email}; String[] ccAddresses = new String[] {'afiugud@hotmail.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('adiez@proclientia.com'); // Specify the name used as the display name. mail.setSenderDisplayName('Salesforce Support'); // Specify the subject line for your email address. mail.setSubject('A new Professional Development order has been placed!'); // 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. mail.setPlainTextBody('Contact Name: ' + ct.Name + '/n' + 'Contact Last Name: ' + ct.LastName + '/n' + 'Contact email: ' + ct.Email + '/n' + 'Contact ID: ' + ct.Id + '/n'); mail.setHtmlBody('<p>Contact Name: ' + ct.Name + '</p>' + '<p>Contact Last Name: ' + ct.LastName + '</p>' + '<p>Contact email: <a href=\'mailto:'+ ct.Email +'\'>'+ ct.Email + '</a></p>' + '<p><hr /></p>' + '<p>Contact ID: ' + ct.Id + '</p>'); // Send the email you have created. Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail }); } }

 

 
 
Thanks in advance.
 
adiez
Salesforce Consulting Partner in Spain
www.proclientia.com