SendMail
Back to ListDescription: Send Email function
FileMaker Prototype:
Set Variable [$res; ACF_Run("SendMail";)]
Category: EMAIL
Dependencies
- emailServerPar: Create a JSON object with the server config for use in E-mail sending.
- PreviewMail: Create HTML version of an Email text stored as markdown format.
NOTE: This function serves as a reference template. To use it effectively, you may need to adjust certain parts of the code, such as field names, database structures, and specific data lists to fit the requirements of your system. This customization allows the function to work seamlessly within your environment.
Function source:
function SendMail ()
string htmlFile = PreviewMail();
string sql, primkey, res, acc = Email_Messages::Email_Account;
JSON params = emailServerPar(acc);
int x;
x = open ( htmlFile, "r");
string htmlContent = read (x);
close (x);
string plainContent = regex_replace ("(<img.+[^>])", Email_Messages::MarkdownText, "") +"\r\n";
plainContent += params["server.PlainSignature"];
params["from"] = Email_Messages::MailFrom;
params["to"] = Email_Messages::Mailto;
if (Email_Messages::Mailcc != "" ) then
params["cc"] = Email_Messages::Mailcc;
end if
if ( Email_Messages::Mailbcc != "") then
params["bcc"] = Email_Messages::Mailbcc;
end if
params["subject"] = Email_Messages::Subject;
params["body.plain"] = plainContent;
params["body.html"] = htmlContent;
// Add attachements
primkey = Email_Messages::PrimaryKey;
ARRAY STRING atts;
sql = "SELECT FilePath FROM Email_Attachements WHERE fk_EmailMessage = :primkey
INTO :atts";
res = ExecuteSQL ( sql);
if (sizeof (atts) > 0) then
params["attachments"] = atts;
end if
// params["debugg"] = "/Users/ole/Desktop/email_debugg_content.txt";
return send_email(params);
end
