Generate Email Automatically using Schedular

How can I customize the scheduler that will generate an email every day at 7 pm with the content of displaying all updated contact records? 

I have done some work and my custom scheduler is showing in the jobs dropdown but I am not getting any email.

custom/Extension/modules/Schedulers/Ext/ScheduledTasks/custom_job.php

And the second file is 

custom/Extension/modules/Scheduler/Ext/Language/en_us.custom_job.php

And it is showing in jobs dropdown

And even did a quick repair and rebuilt. Please let me know what I am doing wrong? 

Parents
  • Hi Hijab Fatima,

    Please make sure you have a cron job setup and running in your server or local machine if the setup is local.

    You can verify this by checking your "Last Successful Run" parameter in Scheduler.

    If it is not set or set to some value in the past, this means your cron job is not running or you have some error in your script.

    Here is the link to setup cron job - https://support.sugarcrm.com/Knowledge_Base/Schedulers/Introduction_to_Cron_Jobs/ 

    and troubleshooting if required - https://support.sugarcrm.com/Knowledge_Base/Schedulers/Troubleshooting_Cron_and_Schedulers/ 

    Also, if you are on sugar latest version, it is recommended to use MailerFactory class instead of SugarPHPMailer for sending emails.

    For eg:

    //setup mailer factory object
    $mailer = MailerFactory::getSystemDefaultMailer();
    $mailer->setSubject('Test Email');
    $mailer->setTextBody('Hi, this is a test email.');
    $mailer->setHtmlBody('<p>Hi, this is a test email.</p>');
    $mailer->clearRecipients();

    //setup recipients
    $mailer->addRecipientsTo(new EmailIdentity('<email_address>', '<recipeint_name>'));
    $mailer->addRecipientsCc(new EmailIdentity('<email_address>', '<recipeint_name>'));
    $mailer->addRecipientsBcc(new EmailIdentity('<email_address>', '<recipeint_name>'));

    //send email now

    $mailer->send();

    Let us know if this helps.

    Regards.

    Hats

Reply
  • Hi Hijab Fatima,

    Please make sure you have a cron job setup and running in your server or local machine if the setup is local.

    You can verify this by checking your "Last Successful Run" parameter in Scheduler.

    If it is not set or set to some value in the past, this means your cron job is not running or you have some error in your script.

    Here is the link to setup cron job - https://support.sugarcrm.com/Knowledge_Base/Schedulers/Introduction_to_Cron_Jobs/ 

    and troubleshooting if required - https://support.sugarcrm.com/Knowledge_Base/Schedulers/Troubleshooting_Cron_and_Schedulers/ 

    Also, if you are on sugar latest version, it is recommended to use MailerFactory class instead of SugarPHPMailer for sending emails.

    For eg:

    //setup mailer factory object
    $mailer = MailerFactory::getSystemDefaultMailer();
    $mailer->setSubject('Test Email');
    $mailer->setTextBody('Hi, this is a test email.');
    $mailer->setHtmlBody('<p>Hi, this is a test email.</p>');
    $mailer->clearRecipients();

    //setup recipients
    $mailer->addRecipientsTo(new EmailIdentity('<email_address>', '<recipeint_name>'));
    $mailer->addRecipientsCc(new EmailIdentity('<email_address>', '<recipeint_name>'));
    $mailer->addRecipientsBcc(new EmailIdentity('<email_address>', '<recipeint_name>'));

    //send email now

    $mailer->send();

    Let us know if this helps.

    Regards.

    Hats

Children