Implement the e-mail sending function

I have a few questions
Among them
For example, let’s say you want to develop a simple booking system.
If you want to send an approval email after receiving a reservation
Can you implement the e-mail sending function from qodly?

Hey Caos,

You can use the Email object to create, send and receive mails using SMTP, IMAP or POP3 servers.

you can find more informations in this link

Hi caos,

You can also easily implement a third party mail service like sendGrid.
Here is a quick code snippet that I use to send an email to one recipient with one optional attachment.
This code can be placed in a sendGrid class to instantiate whenever you need.

// Documentation on https://docs.sendgrid.com/api-reference/mail-send/mail-send
// sendGrid.4qs class
constructor
	property host : string
	property apiKey : string
	
	this.apiKey = PASTE_HERE_YOU_API_KEY
	this.host = "https://api.sendgrid.com/v3"

function sendMail(to: object, subject : string, message : string, attachmentContent: variant, attachmentName : string)
	var content64 : string
	var headers, opts, data : object
	var request : 4D.HTTPRequest
	
	headers = newObject("Authorization", "Bearer "+this.apiKey, "Content-Type", "application/json")
	data = {}
	data.personalizations = []
	data.personalizations.push({to: [{email: to.email, name: to.fullname}]})
	data.from = {email: "sender.declared.on.sendgrid@email.com", name: "John Doe"}
	data.subject = subject
	data.content = []
	data.content.push({type: "text/html", value: message})
	if ((attachmentContent != null) && (attachmentContent != "") && (attachmentName != ""))
		data.attachments = []
		base64Encode(attachmentContent, content64)
		data.attachments.push({content: content64, type: "text/plain",filename: attachmentName})
	end
	
	opts = {method: "POST", headers: headers, body: data}
	request = 4D.HTTPRequest.new(this.host+"/mail/send", opts)
	request.wait()
	if (request.response.status != 202)
		if (undefined(request.response.body.errors[0].message))
			throw(1, request.response.statusText)
		else
			throw(1, request.response.body.errors[0].message)
		end
	end
	webForm.setMessage("Email sent to " + to.email + ". Check your mailbox!")

Usage:

var mailer : cs.sendGrid
mailer = cs.sendGrid.new()
mailer.sendMail({email: "recipient@email.com", fullname: "John Smith"}, "My email title", "My email body text", attachmentContent, "attachmentFilename.ext")

Thank you for your great suggestion

APIs expand the possibilities, don’t they?

I would like to try

1 Like

Yes APIs expand a lot. And this is valid for much more than emails.
You can try this with a Qodly sandbox, there is no feature limitation. Have fun.