
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
-
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?
-
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)
}) -
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
-
>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.
-
Lets check this out. You can book a complementary screensharing session with me via this link:
https://calendly.com/birger-hansen/15minBirger
-
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. -
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 -
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()
-
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? -
@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.