SQLExport as email attachment

Is there a way to attach the SQLExport as an attachment to an email? I tried sending as the body of the email, but after I added two records the email stopped opening with content, not sure if there is a limit or something else going on.

Robb

This works for me (you need to use your own database name and your own email address)

Function Backup()
DBjson=SQLExport(DB, “database.db”, exportComplete)
End Function

Function exportComplete()
JSONExport=JSON.stringify(DBjson)
Call email(EmailAddress,“SQL Backup”,JSONExport)
End Function

Yes, that is what I tried.

When I have no data and only structures, this worked. When I added data to my tables the email stopped being opened and populated. Here is what my email method looks like:

 Function email(t, subject, body)
  location.href="mailto:" & encodeURI(t) & "?subject=" & encodeURI(subject) & "&body=" & encodeURI(body)
End Function

I was thinking that the encodeURI was failing for the body. When debugging the console clears when the export is created so I cannot see what has happened. I get no errors, and no email is opened as it did when I only had only the db schema to be exported.

Ideas?

Yes mine is the same so that is not the problem. Have you tried displaying JSONExport in the console to what the ‘body’ actually looks like ?

There is no guarantee that email will not reformat the body. Attachment is better for that, but not available as a simply command.

How would one look into attaching an attachment? Javascript?

Here is the string and the encoded results. I found if I remove the encodeURI from the body portion the emails opens with the ExportedJSON. What is the possible downfall of not using the encodeURI on the body portion?

I believe the ability to send data as an attachment requires a server side solution (such as PHPMailer, which I use) or use of a 3rd party vendor (typically for a fee).

If removing encodeURI() doesn’t cause you an issue, that’s good, but you may come across a future case where specific characters cause an issue.

Kind regards,
Doug

I am investigating emailjs.com which supports sending emails via js with attachments.

1 Like

PHPMailer is the best option !

Looks interesting - let us know how it goes!

George Henne
NS BASIC Corporation
http://www.nsbasic.com

Easy setup and works as designed. I am able to send an email with attachment all via Javascript, just needed to include a line in the extraheaders. I am liking it so far.

Robb

The php code using PHPMailer is something like this, easy:

<?php //------------------------------------------------------------// // Em PHPmailer - setembro de 2014 // //------------------------------------------------------------// //-----------------------------------// // criar o arquivo antes de envia-lo // //-----------------------------------// $arquivo = $_POST['arquivo']; $usuario = $_POST['usuario']; $email = $_POST['email']; $formato = $_POST['formato']; //--------------------------------------------------------------------------------------------------------------------------------// require 'phpmailer/PHPMailerAutoload.php'; $mail = new PHPMailer; // configuração quando é para o fastmobile email // //$mail->SMTPDebug = 3; // Enable verbose debug output $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'fastmobile.info'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'invent@fastmobile.info'; // SMTP username $mail->Password = 'xxx'; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 290; // TCP port to connect to //------------------------------------------------------------------ $mail->From = 'invent@fastmobile.info'; $mail->addAddress($email); // Name is optional $mail->addReplyTo('invent@fastmobile.info', 'Informação sobre problemas'); //$mail->addCC('sintetik@gmail.com'); $mail->WordWrap = 80; // Set word wrap to 50 characters $mail->addAttachment('INVENT.csv', $usuario.'.'.$formato); // Optional name $mail->isHTML(true); // Set email format to HTML //------------------------------------------------------------------ $mail->FromName = '::: INVENTÁRIO/PICK LIST ::: FASTMOBILE :::'; $mail->Subject = ':: ENVIO DE INVENTÁRIO / PICK LIST ::'; //-------------------- adiciiona a mensagem em html --------------------------------------- $mail->isHTML(true); // Set email format to HTML $mail->MsgHTML(file_get_contents('FASTMOBILE.html')); $mail->addAttachment('fastmobilelogo.png'); if(!$mail->send()) { echo 'Email não enviado...'; echo 'Erro do Mailer #: ' . $mail->ErrorInfo; } else { echo 'Email enviado por [invent@fastmobile.info]'; }

The function encodeURI() encodes special characters, except: , / ? : @ & = + $ #

Use encodeURIComponent() to encode these characters.

http://wiki.nsbasic.com/EncodeURI/decodeURI

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.