How to mail a screen captured image using corona SDK - email

I am new to corona SDK, but I've managed to capture my app scene using the following code:
local function captureArea()
local myCaptureImage = display.captureBounds(display.currentStage.contentBounds, true)
myCaptureImage:removeSelf()
myCaptureImage = nil
end
bg:addEventListener("tap",captureArea)
This works perfectly.
Now I need to send the captured image(with a specific name, say: screen_1.png) to my friend via email. I've used Composing E-mail and SMS for refference, but I fail to understand how I can add this saved image in the attachment field of mail options.
Please give me a proper solution that how can I attach and send the above saved image via email.

display.captureBounds is good for saving the whole screen to the directory. But it usually saves the file with increase in last index. So it may be difficult to read them correctly. So I prefer display.save. But it is not a straight way.
For doing this, you have to:
First create a localgroup.
Then add the screen objects to that group.
Return the display group
Use display.save to save the entire group displayed.
Create mail option and add attachment image from baseDirectory
Call mail Popup
I am giving a sample here:
-- creating the display group --
local localGroup = display.newGroup()
-- creating display objects and adding it to the group --
local bg = display.newRect(0,0,_w,_h)
bg.x = 160
bg.y = 240
bg:setFillColor(150)
localGroup:insert(bg)
local rect = display.newRect(0,0,50,50)
rect.x = 30+math.random(260)
rect.y = 30+math.random(420)
localGroup:insert(rect)
-- Then do as follows --
local function takePhoto_andSendMail()
-- take screen shot to baseDirectory --
local baseDir = system.DocumentsDirectory
display.save( localGroup, "myScreenshot.jpg", baseDir )
-- Create mail options --
local options =
{
to = { "krishnarajsalim#gmail.com",},
subject = "My Level",
body = "Add this...",
attachment =
{
{ baseDir=system.DocumentsDirectory, filename="myScreenshot.jpg", type="image" },
},
}
-- Send mail --
native.showPopup("mail", options)
end
rect:addEventListener("tap",takePhoto_andSendMail)
This will do it...
Keep coding........ :)

Related

Link content type to funtion on Telebot Python

I am building a Telegram Bot using telebot with python. I ask users to updload a picture, for which I created a command "foto". When they do /foto, I ask them to updload a content type "photo". However, they can upload pictures regardless of the command; they just click on upload a picture and that's it. How can I link the "upoload photo" to the command, so that they can only upload a picture after writing "/foto"?
#bot.message_handler(commands=['foto']) def send_welcome(message,
chat_id):
chat_id = message.chat.id
send = bot.send_message(message.from_user.id, 'Subí tu foto.')
bot.register_next_step_handler(send, photo())
return
#bot.message_handler(content_types=["photo"]) def photo(message):
fileID = message.photo[-1].file_id
logger.info("User_id, fileID", message.from_user.id, fileID)
file_info = bot.get_file(fileID)
#print('file.file_path =', file_info.file_path)
downloaded_file = bot.download_file(file_info.file_path)
with open(f"./images/{fileID}.jpg", 'wb') as new_file:
new_file.write(downloaded_file)
send = bot.send_message(message.from_user.id, 'Foto recibida, gracias!')
As far as i know you cant restrict users from sending files
what you can do is to capture the files only after the command is used
for more info please read docs

Email Pdf attachments to Google sheet

I am looking for something that allows me from a mail PDF attachment to get a data in a google sheet.
We all often get PDF attachments in our email and it will be great if we get the entire data in a google sheet.
DO let me know if there is anything like this
Explanation:
Your question is very broad and it is impossible to give a specific answer because that answer would depend on the pdf but also on the data you want to fetch from that, besides all the other details you skipped to mention.
Here I will provide a general code snippet which you can use to get the pdf from the gmail attachments and then convert it to text (string). For this text you can use some regular expressions (which have to be very specific on your use case) to get the desired information and then put it in your sheet.
Code snippet:
The main code will this one. You should only modify this code:
function myFunction() {
const queryString = "label:unread from example#gmail.com" // use your email query
const threads = GmailApp.search(queryString);
const threadsMessages = GmailApp.getMessagesForThreads(threads);
const ss = SpreadsheetApp.getActive();
for (thr = 0, thrs = threads.length; thr < thrs; ++thr) {
let messages = threads[thr].getMessages();
for (msg = 0, msgs = messages.length; msg < msgs; ++msg) {
let attachments = messages[msg].getAttachments();
for (att = 0, atts = attachments.length; att < atts; ++att) {
let attachment_Name = attachments[att].getName();
let filetext = pdfToText( attachments[att], {keepTextfile: false} );
Logger.log(filetext)
// do something with filetext
// build some regular expression that fetches the desired data from filetext
// put this data to the sheet
}}}
}
and pdfToText is a function implemented by Mogsdad which you can find here. Just copy paste the code snippet provided in that link together with myFunction I posted in this answer. Also you have some options which you can use that are very well explained in the link I provided. Important thing to note, to use this library you need to enable the Drive API from the resources.
This will get you started and if you face any issues down the road which you can't find the solution for, you should create a new post here with the specific details of the problem.

BizTalk Orch/SMTP - Microsoft.XLANGs.BaseType.Content must be a message property of

This is related to my question from 2017: How Set Attachment Name to Show Properly in Outlook
This time, I have an orchestration with the following in a construct shape:
attachmentName = System.IO.Path.GetFileName(
msg_Ledger6002_File_XmlDoc
(FILE.ReceivedFileName));
msg_Email.BodyPart = new ABC.Ledger6002.Component.RawString("See attached email.");
msg_Email.AttachmentPart = msg_Ledger6002_File_XmlDoc;
// attachmentName is set earlier in orch so we could write it to EventLog for debugging
msg_Email.AttachmentPart(MIME.FileName) = attachmentName;
//msg_Email.AttachmentPart(MIME.ContentDescription) = "body";
//msg_Email.AttachmentPart(MIME.ContentTransferEncoding) = "base64";
// These are working
msg_Email(SMTP.Subject) = "Ledger6002 File";
msg_Email(SMTP.SMTPTo) = msg_Config_Email.smtpToEmail;
msg_Email(SMTP.From) = msg_Config_Email.smtpFromEmail;
msg_Email(SMTP.SMTPAuthenticate) = 0; // do not authenticate to SMTP server
// trying these two new parms below
msg_Email(SMTP.EmailBodyTextCharset) = "UTF-8";
msg_Email(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
The last line above gives me an expression shape not valid, and when I mouse over it it says identifies the error as:
Microsoft.XLANGs.BaseType.Content must be a message property of
msg_email.
Before I added the two lines under the comment "trying these two new parms below", I am getting an email with the desired attachment. The problem is that it is just called "body" and when I do "save as" from Outlook, it wants to call it "body" instead of the name of the file I dropped.
I'm using a "specify later" statically configured SendPort with PassThru for the Pipeline. I have tried a pipeline with MimeEncoder, but that caused the attachment to appear in the body. I would like to move to a dynamic pipeline, but so far I've got the static one working except for the name assigned to the file attachment.
To fix the error: "Microsoft.XLANGs.BaseType.Content must be a message property of msg_email.", I just needed to include the part name (the message is associated with a multipart message type, and I didn't include the partname):
Wrong:
msg_Email(Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
Right:
msg_Email.BodyPart (Microsoft.XLANGs.BaseTypes.ContentType) = "text/plain";
I'm still working on getting the email with attachment to come out correctly, but so far this post https://social.msdn.microsoft.com/Forums/en-US/988b0d91-1e5a-4f73-b30d-417d6ea9fa75/attachment-name-in-outlook-is-ok-see-on-exchange-always-named-body?forum=biztalkgeneral seems to be the best explanation.

How do I flag email for recipients with Outlook APIs in MATLAB?

I want to send an email via the Outlook API in MATLAB and I also want to create a task in the recipients' Outlook.
I have tried taking a look at the Outlook API documentation, but all I could find was a reference to 'FlagStatus', which is not a parameter available for 'olMail'.
% Connect to Outlook
outlook = actxserver( 'outlook.Application' );
% Create email
email = outlook.CreateItem( 'olMail' );
% Add email properties
email.To = address;
email.Subject = subject;
email.Importance = 'olImportanceHigh';
email.BodyFormat = 'olFormatHTML';
email.HTMLBody = body;
% Add task properties
email.TaskSubject = taskName;
email.TaskStartDate = datestr( today, 'dd/mm/yyyy' );
email.TaskDueDate = datestr( today + 12, 'dd/mm/yyyy' );
% Set reminder
email.ReminderSet = true;
email.ReminderTime = datestr( today + 7 + 9/24, 'dd/mm/yyyy hh:MM' );
% Send email
email.Send;
The expected behavior would be the same as selecting the option as below:
I believe this is related to the FlagRequest property. To see what it does, run email.Display() after executing your code - you should notice an Outlook "new message" window open. This is what you would see initially,
Then, if you execute:
% Flag for recipient
email.FlagRequest = "<NAME OF FLAG HERE>";
You'd get:
... which is the same message that would appear when setting this flag manually through the Outlook GUI. Two caveats:
If you open the flag menu after running the command, it would show that a local flag would be created, instead of a remote one. This looks like an outlook bug.
The remote flag time/date is what you put in ReminderTime. I think it would be better to set FlagRequest before ReminderSet and ReminderTime for it to be reflected correctly in the GUI (when using email.Display).

Generate and send pdf through Google Forms to my email address - doesn't send, debugging to no assitance

I'm trying to send myself a form-based report as a pdf. The problem is, I don't receive any emails. Debugging doesn't help much, since that only tells me which values are "undefined" (they are being defined the instant one fills out the form and triggers the email by clicking send; in theory). My coding experience stems from the days of TurboPascal and .bat-files, and I have lately realised I need to shape up. Trying to figure out Android, and this is a little experiment at work. But I had forgotten the lost feeling of "what now?"...
Here's the code:
// Samfunnsutvikling kursrapport
var docTemplate = "TemplateIDinGoogleDoks";
var docName = "Kursrapport";
// When Form Gets submitted
function onFormSubmit(e) {
//Get information from form and set as variables
var email = "worker#work.no";
var namn = e.namedvalues.namn;
var arrangement = e.namedvalues.arrangement;
var dato = e.namedvalues.dato;
var referat = e.namedvalues.referat;
// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DocsList.getFileById(docTemplate)
.makeCopy(docName+' for '+namn)
.getId();
// Open the temporary document
var copyDoc = DocumentApp.openById(copyId);
// Get the document’s body section
var copyBody = copyDoc.getActiveSection();
// Replace place holder keys,in our google doc template
copyBody.replaceText('keynamn', namn);
copyBody.replaceText('keyarrangement', arrangement);
copyBody.replaceText('keydato', dato);
copyBody.replaceText('keyreferat', referat);
// Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
var subject = "Kursrapport";
var body = "Kursrapporten frå " + namn + "";
GmailApp.sendEmail(email, subject, body, {htmlBody: body, attachments: pdf});
// Delete temp file
DocsList.getFileById(copyId).setTrashed(true);
}
The script/document is authorized to send emails, but, oddly, I had to authorize it twice. It is saved.
In general, you can add Logger.log() to print variable values or just messages to see how far does it reach.
It looks as attachments parameter expects Blob[] type, however you are passing just Blob. So, it should be:
GmailApp.sendEmail(email, subject, body, {htmlBody: body, attachments: [pdf]});
You may also want to replace DocsList with DriveApp class as-is since the first one is depricated.
Update
It turned out also that getActiveSection() was renamed to getBody().