how to send email from matlab??

조회 수: 15 (최근 30일)
AYUSH RAJ ACHARYA
AYUSH RAJ ACHARYA 2018년 4월 19일
답변: Rajanya 2024년 8월 9일
I have tried for the article posted by matlab but get many error mainly
Could not connect to SMTP host: 'my IP address', port: 'my port number'; Connection refused: connect
the code used was
mail: my email
password : my password
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(mail,'Test from MATLAB','Hello! This is a test from MATLAB!')

답변 (1개)

Rajanya
Rajanya 2024년 8월 9일
I was able to reproduce the issue with ‘sendmail()’ that you probably are facing. Maybe you could try adding the server details along with the mail address and password using ‘setpref(.)’.
Here’s how you can achieve it:
server = 'smtp-mail.outlook.com'; %(if you are using outlook)
setpref('Internet','SMTP_Server', server);
This should solve your issue in establishing a connection.
An alternative can also be to use TLS instead of SSL. TLS generally works on port 587 unlike SSL which works on 465. An example code could be like:
mail='your_mail_address';
password='your_password';
server = 'smtp-mail.outlook.com';
Subject = 'Some_subject';
Text = 'Some_text';
setpref('Internet','E_mail', mail);
setpref('Internet','SMTP_Server', server);
setpref('Internet','SMTP_Username', mail);
setpref('Internet','SMTP_Password', password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.port', '587');
props.setProperty('mail.smtp.starttls.enable','true');
sendmail('recipient_mail_address', Subject, Text)
Point to note: MATLAB’s ‘sendmail’ does not work with Gmail as it will be having authentication issues. You will need to “Allow less secure apps” in your account settings before setting up a connection on the Gmail server.
Feel free to reach out if you have any further queries regarding this.

카테고리

Help CenterFile Exchange에서 Web Services에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by