I am attempting to send an email to a virtual fax number from GAS MailApp. The email sends with the attachment and everything looks perfect, but for some reason it doesn't see the attachment. I also sent one to the same address from my gmail directly and it goes through. Look at the source, it looks like the biggest difference is that there is no X-Attachment-Id or Content-ID. No idea if this makes a difference.
Regular email
Content-Type: application/pdf; name="000106.pdf" Content-Disposition: attachment; filename="000106.pdf" Content-Transfer-Encoding: base64 X-Attachment-Id: f_kjyo04nj0 Content-ID: <f_kjyo04nj0>
Email from MailApp
Content-Type: application/pdf; name="000106.pdf" Content-Disposition: attachment; filename="000106.pdf" Content-Transfer-Encoding: base64
Code.gs
function doGet() { return HtmlService.createTemplateFromFile('forms').evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME) .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL); } function sendFax(data, file, faxto) { try { var contentType = data.substring(5, data.indexOf(';')), bytes = Utilities.base64Decode(data.substr(data.indexOf('base64,') + 7)), blob = Utilities.newBlob(bytes, contentType, file); MailApp.sendEmail(faxto + "@virtualfaxaddress.com", "faxaccesscode", "", { attachments: blob }); return 'Sent!'; } catch (f) { return f.toString(); } }
forms.html
<!DOCTYPE html> <html> <head> <base target="_top"> <script src="https://code.jquery.com/jquery.min.js"></script> </head> <body> <body> <div class="center"> <div class="fax-form"> <form method="post"> <label for="faxto">Fax to #:</label><br> <input type="tel" name="faxto" id="faxto"><br><br> <label for="upload">Choose a file to upload:</label> <input type="file" name="upload" id="upload" accept=".pdf, .jpg, .tiff, .png, .bmp, .gif, .rtf, .txt, .doc, .docx, .xls, .xlsx, .ppt, .pptx"><br><br> <input type="button" value="Submit" id="submit" onclick="submitForm()"> </form> <p id="progress"></p> </div> </body> </body> <script> var file, reader = new FileReader(); // Upload the file to Google Drive reader.onloadend = function (e) { google.script.run .withSuccessHandler(showMessage) .sendFax( e.target.result, file.name, $('input#faxto').val() ); }; // Read the file on form submit function submitForm() { file = $('#upload')[0].files[0]; showMessage('Uploading file..'); reader.readAsDataURL(file); } function showMessage(e) { $('#progress').html(e); } </script> </html>
Does anyone know the role these IDs play in a situation like this? Could this be the cause? If so, how would I go about fixing it so that MailApp sends attachment with IDs?
https://stackoverflow.com/questions/65744611/google-apps-script-to-gotoconnect-jive-virtual-fax-not-finding-attachment-fr January 16, 2021 at 06:55AM
没有评论:
发表评论