Error in sending mail through matlab
40 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Im trying to send a mail through matlab but im keep getting this error
my code was like
mail = 'myuniversitymail@univ.edu';
password = 'mypassword';
mailingList = {'receivermail@gmail.com'};
server = 'smtp-mail.outlook.com';
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.port','587');
props.setProperty('mail.smtp.starttls.enable','true');
props.setProperty('mail.smtp.ssl.trust', '*')
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server',server);
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
messageBody = sprintf(' Good morning ');
messageBody = sprintf('%s\n\n Here is the data analysis from yesterdays data. Have a great day!', messageBody);
messageBody = sprintf('%s\n\n\n *This email was generated and sent automatically via MATLAB', messageBody);
sendmail(mailingList,"Data Analysis",messageBody,filename);
And the error is like,
Error using sendmail (line 184)
Can't send command to SMTP host;
No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
Error in project (line 73)
sendmail(mailingList,"Data Analysis",messageBody,filename);
Pls help me to resolve this issue asap....
0 comentarios
Respuestas (1)
Nivedita
el 3 de Mayo de 2024
Hi Anandha,
The error message you are encountering suggests an issue with the security protocol used by MATLAB to establish a connection with your SMTP server. This can occur due to a mismatch between the security requirements of the SMTP server and the capabilities/configuration of the MATLAB environment.
Ensure that your network or firewall settings are not blocking the connection to the SMTP server. Some institutions have strict network policies that might block certain outbound connections.
You can try using a different email service (e.g., Gmail's SMTP server) with its corresponding settings as follows:
mail = 'sender_address@gmail.com'; % Your Gmail address
password = 'sender_password'; % Your Gmail password
mailingList = {'receiver_address@gmail.com'}; % Recipient's email address
server = 'smtp.gmail.com'; % Gmail's SMTP server
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.port','587'); % Use 465 for SSL
props.setProperty('mail.smtp.auth','true'); % Enable authentication
props.setProperty('mail.smtp.starttls.enable','true'); % Enable STARTTLS
props.setProperty('mail.smtp.ssl.trust', 'smtp.gmail.com'); % Trust the Gmail SMTP server
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server',server);
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
messageBody = sprintf('Good morning');
messageBody = sprintf('%s\n\nHere is the data analysis from yesterday''s data. Have a great day!', messageBody);
messageBody = sprintf('%s\n\n\n*This email was generated and sent automatically via MATLAB', messageBody);
% Assuming 'filename' is defined elsewhere in your script
sendmail(mailingList, "Data Analysis", messageBody, filename);
If you have 2-Step Verification enabled on your Google account (which is highly recommended for security reasons), you cannot use your regular password. Instead, you will need to generate an App Password specifically for use in your MATLAB script.
You can try to directly access the App Passwords page by using this URL: https://security.google.com/settings/security/apppasswords
Generate a 16 character password and use it instead of your regular password in the code above. It should work.
0 comentarios
Ver también
Categorías
Más información sobre Web Services en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!