Sending email from custom module

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • malg
    Junior Member
    • Jun 2023
    • 24

    Sending email from custom module

    Heya

    We currently have a custom module (package) and we've setup a workflow to send an SMS to the user when a specific drop down changes.

    We're wanting to use a manual button at the top to send an email to the contact with a specific field from the custom module record, but it keeps either getting stuck in 'sending' with a value of 0, or is not sending at all.

    Below is what we're working with, any suggestions would be great!

    Thanks

    Matt

    (We've changed email address here from our actual one)



    Code:
    $refPackage = string(refpack); // force to string
    $contactEmail = contact.emailAddress;
    $fromEmail = 'accounts@yourdomain.com';
    
    $subject = 'Your Reference';
    $body = 'Heya - your reference number is: ' + $refPackage + '. Please check your documents for confirmation.';
    
    $emailId = record\create(
    'Email',
    'to', $contactEmail,
    'from', $fromEmail,
    'subject', $subject,
    'body', $body,
    'isHtml', false,
    'direction', 'outbound',
    'status', 'Sending',
    'type', 'Outbound',
    'assignedUserId', createdById,
    'parentType', 'Contact',
    'parentId', contact.id
    );
  • rabii
    Active Community Member
    • Jun 2016
    • 1285

    #2
    there is no fields (direction and type) by default in espocrm. are these custom fields ?
    Rabii
    Here to help :)

    Comment

    • malg
      Junior Member
      • Jun 2023
      • 24

      #3
      No, from a previous CRM system I assumed they may be needed - I'll remove them and retry

      Comment

      • rabii
        Active Community Member
        • Jun 2016
        • 1285

        #4
        Remove them as they are not default field in email entity. also not sure if you shared all the code but i can't see the code that does send the email once it is created.

        Here is an example from documentation

        PHP Code:
        $id record\create(
            
        'Email',
            
        'from''from-address@test.com',
            
        'to''to-address@test.com',
            
        'subject''Test from formula',
            
        'body''Hi,\n\nThis is a test.',
            
        'isHtml'false,
            
        'status''Sending'
        );
        ext\email\send($id); 
        Rabii
        Here to help :)

        Comment

        • malg
          Junior Member
          • Jun 2023
          • 24

          #5
          We re-wrote the script - we had the last row in but omitted from the snippet

          Thanks for your help, we found the issue

          Comment

          Working...