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
-
The "from:" parameter has to be an email registered in this team. so it would be:
–––
from: text(userEmail(user()))
–––
Birger
-
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
-
Thanks Birger!
I will try it out as soon as possible.
-
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?
-
Found the problem! I messed up with the learning!
-
>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
-
@Westy,
I'm facing the same problem.
Have you found the problem?
Thanks
-
...solution
-
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. -
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.
-
Yep, removing the "do as server" step does the job!
Thanks
-
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?
-
Something like this:
alert("Email has been send");
'Date / Time' := now()
-
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? -
oops, sorry... Change the "end" order
...
end
end;
alert("Email has been send");
'Date / Time' := now()
end
-
or
end;
alert("Email has been send");
'Date / Time' := now()
endend
-
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 -
});
alert("Email has been send");'Email Sent Date' := now()
end
end -
That did it Nick!
Could you explain why it had to be structured this way?
-
@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
- 12614Views