0

Button to send mail and attachment PDF

Hi at everyone,

I’m using this code in a button to send mail with text and the record in pdf as attachments, the problem is Ninox follow like charge and not working, I have a basic account, any suggestion?

let myPdf := printAndSaveRecord(this, "Print Layout Name");
let myName := "Name of file.pdf";
importFile(this, myPdf, myName);
let myEmail := userEmail(user());
sendEmail({
from: "test@email.com",
to: "test@email.com",
cc: "test@email.com",

bcc:"Test@email.com",

subject: "Here's a lead please follow up on " + 'Company Name',
text: "Please contact Lead attached" + Status,
html: "<h1>Here's a lead please follow up</h1><i>Please contact Lead attached </i>",
attachments: file(this, myName)
})

Thanks a lot

33 replies

null
    • Birger_H
    • 5 yrs ago
    • Reported - view

    The "from:" parameter has to be an email registered in this team. so it would be:

    –––
    from: text(userEmail(user()))
    –––

    Birger

    • Alfredo_A
    • 5 yrs ago
    • Reported - view

    Hello Birger,
    I am using a code I got from another of your very useful replies but still cannot get Chrome to send an e-mail.  It seems like Ninox spends some time thinking and then nothing happens.

    let Bijlagen := null;
    let myLayout := "Asignacion comercial";
    let myNumber := cnt(files(this)) + 1;
    let myName := "Fidelizacion - " + Inquilino.'Nombre Completo Persona' + " " + format(date(today()), "YYYYMMDD") + ".pdf";
    importFile(this, printAndSaveRecord(this, myLayout), myName);
    Bijlagen := file(this, myName);
    let myHtml := "<h1>This is a test</h1>"
    sendEmail({
    from: userEmail(user()),
    to: text(Asesor.Email),
    subject: "Ninox",
    text: text(myHtml),
    html: myHtml,
    attachments: Bijlagen
    })

    Alternatively, can I send an attachment from the e-mail intelligent field?

    • Alfredo_A
    • 5 yrs ago
    • Reported - view

    I also tried this other coe with the same results:

    let myPdf := printAndSaveRecord(this, "Print Layout Name");
    let myName := "Name of file.pdf";
    importFile(this, myPdf, myName);
    let myEmail := userEmail(user());
    sendEmail({
    from: "test@email.com",
    to: "test@email.com",
    cc: "test@email.com",

    bcc:"Test@email.com",

    subject: "Here's a lead please follow up on " + 'Company Name',
    text: "Please contact Lead attached" + Status,
    html: "<h1>Here's a lead please follow up</h1><i>Please contact Lead attached </i>",
    attachments: file(this, myName)
    })

    • Birger_H
    • 5 yrs ago
    • Reported - view

    You are creating the attached ducument locally (on your machine). Next you tell the server to send a mail. The requested attachment is not yet availale when the mail is to be send. Try this:
    –––
    let me := this;
    do as server
    let Bijlagen := null;
    let myLayout := "Asignacion comercial";
    let myNumber := cnt(files(me)) + 1;
    let myName := "Fidelizacion - " + me.Inquilino.'Nombre Completo Persona' + " " + format(date(today()), "YYYYMMDD") + ".pdf";
    importFile(me, printAndSaveRecord(this, myLayout), myName);
    Bijlagen := file(me, myName);
    let myHtml := "<h1>This is a test</h1>"
    sendEmail({
    from: userEmail(user()),
    to: text(me.Asesor.Email),
    subject: "Ninox",
    text: text(me.myHtml),
    html: me.myHtml,
    attachments: Bijlagen
    })
    end
    –––

    Birger

    • Alfredo_A
    • 5 yrs ago
    • Reported - view

    Thanks Birger!

    I will try it out as soon as possible.

    • Alfredo_A
    • 5 yrs ago
    • Reported - view

    Hello Birger,

    I implemented your code and probably made a mistake.  Now I am receiving an email every minute -literally.  I have deleted the code, the button and any other reference and am still getting it.  Any idea what might be causing this?

    • Alfredo_A
    • 5 yrs ago
    • Reported - view

    Found the problem! I messed up with the learning!

    • Choices_Software_Dean
    • 5 yrs ago
    • Reported - view

    >The requested attachment is not yet availale when the mail is to be send<

    Hello Birger,

    I created a new project on the Ninox cloud that only contains a single text field and a print preview layout named "Asignacion comercial".  I attached your above code to a button and changed the "to" email address to my own email address and, assigned "my.pdf" to the "myName" variable. When I click the button an email is sent to me with an attachment, but the attachment has 0 bytes. What might I be doing wrong?

    I am using: The Ninox Public Cloud, Chrome, and Windows 10.

    • Birger_H
    • 5 yrs ago
    • Reported - view

    Lets check this out. You can book a complementary screensharing session with me via this link:
    https://calendly.com/birger-hansen/15min

    Birger

    • Nick
    • 5 yrs ago
    • Reported - view

    @Westy,

    I'm facing the same problem.

    Have you found the problem?

     

    Thanks

    • Nick
    • 5 yrs ago
    • Reported - view

    ...solution

    • Choices_Software_Dean
    • 5 yrs ago
    • Reported - view

    My recollection is that it worked without the "do as server" code. Another related issue, that to my knowledge  is still unresolved, is attachments having 0 bytes when the script that sends the email is contained within a new or updated record action. This has kept us from using Wufoo/Zapier to send emails with attachments.

    • Choices_Software_Dean
    • 5 yrs ago
    • Reported - view

    I just confirmed it in a new test solution. Removing "do as server" and "end" and substituting my email address as recipient and my print preview name, in the sample code from prior page works.

    • Nick
    • 5 yrs ago
    • Reported - view

    Yep, removing the "do as server" step does the job!

    Thanks 👍

    • Halio
    • Halio
    • 5 yrs ago
    • Reported - view

    What code can be added to get an alert() message stating the email has been sent and having a time & date field filled out with the sent time & date?

    • Nick
    • 5 yrs ago
    • Reported - view

    Something like this:

     

    alert("Email has been send");

    'Date / Time' := now()

    • Halio
    • Halio
    • 5 yrs ago
    • Reported - view

    Thank you for your quick reply Nick!
    I'm not sure where in my code I should add those two lines. I tried a few places but Ninox isn't happen. Could you give me some additional pointers.

    if not Recipient then
    alert("You have no recipient, please add one before sending this email!")
    else
    if not Subject then
    alert("Subject line is empty, please don't leave it blank.")
    else
    sendEmail({
    from: userEmail(),
    to: Recipient,
    cc: 'Copy [CC]',
    bcc: 'Blind Copy [BCC]',
    replyTo: 'Reply to',
    subject: Subject,
    text: "This",
    html: Body,
    attachment: Attachments
    })
    end
    end

    • Nick
    • 5 yrs ago
    • Reported - view

    Hi Halio,

    if not Recipient then
    alert("You have no recipient, please add one before sending this email!")
    else
    if not Subject then
    alert("Subject line is empty, please don't leave it blank.")
    else
    sendEmail({
    from: userEmail(),
    to: Recipient,
    cc: 'Copy [CC]',
    bcc: 'Blind Copy [BCC]',
    replyTo: 'Reply to',
    subject: Subject,
    text: "This",
    html: Body,
    attachment: Attachments
    })
    end
    end;

    alert("Email has been send");

    'Date / Time' := now()

    • Halio
    • Halio
    • 5 yrs ago
    • Reported - view

    Nick, it kinda worked except now the last alert seems to override the other alerts I had built in. Now I can press the send email button and it gives me only that last alert, notifying me that the email has been sent even though there are no recipients and the subject line is left blank. 
    How can I make sure that last alert does not interfere with the other prerequisites?

    • Nick
    • 5 yrs ago
    • Reported - view

    oops, sorry... Change the "end" order

     

    ...

    end

    end;

    alert("Email has been send");

    'Date / Time' := now()

    end

    • Nick
    • 5 yrs ago
    • Reported - view

    or

     

    end;
    alert("Email has been send");
    'Date / Time' := now()
    end

    end

    • Halio
    • Halio
    • 5 yrs ago
    • Reported - view

    Neither options were accepted by Ninox but a modified version of your two suggestions did work [code below]. Now it checks for recipients but it does not verify a blank subject line. What am I missing?


    })
    end;
    alert("Email has been sent.");
    'Email Sent Date' := now()
    end

    • Nick
    • 5 yrs ago
    • Reported - view

    });
    alert("Email has been send");

    'Email Sent Date' := now()
    end
    end

    • Halio
    • Halio
    • 5 yrs ago
    • Reported - view

    That did it Nick!

    Could you explain why it had to be structured this way?

    • Choices_Software_Dean
    • 5 yrs ago
    • Reported - view

    @Halio, you can do:

     

    let message := sendEmail({from: userEmail(user()),
    to: text('Send To'),
    subject: text(Subj),
    text: text(me.myHtml),
    html: me.myHtml,
    attachments: files(this)
    });
    alert(message);

     

    The sendEmail will return error messages. I am not sure if no message returned will always mean that the email was sent. Maybe someone else can comment on that.

Content aside

  • 3 yrs agoLast active
  • 33Replies
  • 12573Views