Button to send mail and attachment PDF
I

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

Ninox Profile

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

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

Birger

Ninox Profile

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?

Ninox Profile

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)
})

Ninox Profile

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

Ninox Profile

Thanks Birger!

I will try it out as soon as possible.

Ninox Profile

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?

Ninox Profile

Found the problem! I messed up with the learning!

 

Ninox Profile

>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.

Ninox Profile

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

Birger

1 2
Reply