sendmail works when I run my app but not when another user uses it in a packaged app

Hello,
I made an app in app designer and part of the app asks the user to input their e-mail address and then the app sends them a "report" of sorts at the end of using the app when they push a "submit" button. The code I write is below.
The issue here is that when I push the submit button, it works and sends me the e-mail. When I sent it out to a friend to test drive, it gave them a "ding" and didn't send the e-mail. Is there anything not packaged up with the app when you create a standalone desktop app that might prevent that functionality?
data={1:10}
out_email=input('email','type the recipient email');
filename=['testing.xlsx'];
filepath=[cd '\' filename];
writecell(data,filepath);
user = getenv('username');
mail = 'myemail@gmail.com'; %my ghost GMail email address
password = 'mypassword'; % ghost GMail password
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
sendmail(out_email{:},'Results',{'testing'},filepath)
delete(filepath) %I don't want the user to necesarrily have a copy of the file stored for them - only sent to the provided email
Looking forward to suggestions/thoughts.
Thanks

 Respuesta aceptada

They probably need to enable gmail "Less Secure Apps" in order for MATLAB to send to gmail .

16 comentarios

I looked into that and my understanding is that setting has to be adjusted for the senders e-mail address, not the recipient.
Other thoughts?
Hmmm, that's a good point.
It says that the sender needs to disable 2FA if you want to use Less Secure Apps. That's a bit of a hassle just to send an mail.
I am actually curious about this. Maybe you can set up the mail for the task and send the files to yourself (or the same mail, which is a tiny bit insecure if users can see the password for the mail), this way users don't need to fill their user data to some "unknown" script.
Or something like this, or FTP, or copy file to shared network folder.
So I made a ghost email account - not my main - so I don’t need to worry so much about the security issues and then allowed the less secure app access. I don’t plan on ever receiving anything to that email - just for sending results to users.
The use for the app by its nature requires me to allow users to specify where they want to send the results without being able to see them (ie, students sending responses to their instructor).
I see, that comment was a bit misleading for me
%my GMail email address
%Your GMail password
Apologies - updated the comments
What about filepath?
filepath=[cd '\' filename];
sendmail('usere-mail@gmail.com','Results',{'testing'},filepath)
I didn't see that one gets confirmation if the mail was sent or not, so maybe it's the attachment problem, maybe cd returns totally different directory than expected.
Or java doesn't get packaged when you create standaloneapp.
Filepath shouldn’t be the problem I think. Whatever the directory is, it should save the file there and then delete the file after sending the email. I wonder what the CD is for someone using the app from their desktop... I’ll look into it.
I was curious about the java dependencies being included in the package... anyone know about this?
@Mario Malic
The
cd
from an installed app without MATLAB on the computer is the location where the program was run. That's the folder where you installed the program, or the desktop if you made a shortcut. So it seems like this isn't the issue. The filepath is sound.
Any idea if the java dependencies are included included in the package?
Only the sender email needs to change setttings to be less secure.
I have the same setup where a "ghost" email address on gmail was set up solely to send emails from Matlab. I have analyses that take days to complete and they send me an email when they are done.
I've written instructions how to set this up here:
@Adam Danz
The e-mails work beautifully when I run the program myself (following guidance from your linked post above) - but when I packaged it using MATLAB Compiler, and gave it to a non-MATLAB user, they reported hearing a "ding" when they tried to generate the e-mail (which I assume is an error), and no e-mail was sent.
The only explanation I have for now is that that individual doesn't have java on their machine EDIT: and that MATLAB doesn't package java dependencies needed for sendmail in the packaging process using compiler:
I added a few lines of code the give an error mesage if java isn't detected
if ~usejava('jvm')
error('MATLAB:sendmail:NoJvm','SENDMAIL requires Java. File saved to selected desktop directory');
else
%sendmail code recommended above by Adam Danz
end
So I'll see if it still gives the error with that, or if that settles it that code requiring java may not work in packaged apps on machines without java installed.
You may have found the problem.
Firewall and antivirus software are another frequent problem. I've listed some threads that deal with this issue in a comment under my answer I mentioned earlier.
I'm not sure if the compiler is causing the problem or not.
Everyone - thanks for the contributions.
Matlab compiler does include a version of JVM that will allow the sendmail function to work. The error received by the beta tester was unrelated to this issue and had to do with permissions on the machine - not a limitation we went into here.
All in all this is solved now and working just fine.
Nearly all of the sendemail errors I've seen are either from incorrect syntax/inputs or with software on local machines that are blocking it (which is usually a good thing). Thanks for letting us know what the probem was, Shae.
@Adam Danz @Walter Roberson
Sending the e-mail works now on windows machines, but not on MAC. I've compiled the app for mac, but when users install the program, it gets hung up on the line of code where you set preferences:
setpref('Internet','SMTP_Server','smtp.gmail.com');
Any idea if the name of preference information is different on a OS X compared to PC?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Preguntada:

el 12 de Sept. de 2020

Comentada:

el 16 de Oct. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by