I need to send an email via MATLAB and I've read the instructions for sendmail and lots of answers around here. I've tried 3 email providers and I can't really use any of them:
Gmail: I can only send email when I deactivate my anivirus
Hotmail and Yahoo: Error using sendmail (line 171) Exception reading response; Connection reset
Hotmail and Yahoo (antivirus off): Error using sendmail (line 171) Exception reading response; Unrecognized SSL message, plaintext connection?
Here's the code
mail = 'user#service.com';
password = 'passwordgoeshere';
setpref('Internet','SMTP_Server','smtp.server.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',port);
sendmail(mail,'Test from MATLAB','Hello! This is a test from MATLAB!')
I've used the following variables:
Gmail: smtp.gmail.com port=465
Hotmail: smtp.live.com port=465 and port=587
Yahoo: smtp.mail.yahoo.com port=587
Since deactivating the antivirus is not a good option, can anyone help me solving this?
Thank you
An alternative way on linux is to run a command line that send the email.
unix('echo "message" | mail -s "subject" example#gmail.com');
A similar method should be available for windows.
For Gmail
Change your settings to allow less secure apps to access your account. Go to the "Less secure apps" section in My Account.
Next to "Access for less secure apps," select Turn on. (Note to Google Apps users: This setting is hidden if your administrator has locked less secure app account access.)
In Matlab:
mail = 'user#otherdomain.com';
password = 'myPassword';
% Set up the preferences
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
% The following is necessary only if you are using GMail as
% your SMTP server.
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');
subject = 'Test subject';
message = 'Test message';
sendmail(mail,subject,message)
Simply declare
mail = 'user';
Drop the extension #service.com for the variable mail.
Related
I am using CI library to send an email using Sendgrid smtp.
but it is not giving any response, neither email is sending.
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.sendgrid.net';
$config['smtp_user'] = 'api key name';
$config['smtp_pass'] = 'api key';
$config['smtp_port'] = '587';
$config['smtp_keepalive'] = 'TRUE';
$this->email->initialize($config);
$this->email->from('test#test.com', FROM_NAME);
$this->email->to($email);
extract($arr_var);
$sub=addslashes($row['subject']);
eval("\$subject= \"$sub\";");
$body=addslashes($row['message']);
eval("\$message= \"$body\";");
if ($subject!='') {
$this->email->subject(stripslashes($subject));
} else {
$this->email->subject($row['subject'].' - '.$this->config->item('app_title'));
}
$this->email->message($message);
$bool=$this->email->send();
Using above code i am sending en email CI v3 but it I am not receiving any email?
Twilio SendGrid developer evangelist here.
Two things stand out to me here.
First, where you set the smtp username, it should be the string "apikey" (see the instructions for sending with SMTP here).
Second, the from address you are sending from is "test#test.com". SendGrid requires you to verify the identity you send from. You either need go through Single Sender Verification or Domain Authentication and then use an email address that you have verified to send the emails from.
Once you have sorted those two bits out, your emails should send successfully.
The mails are sent with default From address as wasadm#servername which I want to change. I tried using the property mailFrom at application.inf file, changed the values at websphere console - Resources >> Mail >> Mail Sessions >> Return e-mail address but nothing worked out.
Could you please let me know if you have some solution to replace the default from mail address to a custom value.
Normally, the email-sending application code sets a "from" address in the message itself.
That said, I think it might work to set a Mail Session Custom property of mail.from. According to https://javaee.github.io/javamail/docs/api/overview-summary.html:
mail.from The return email address of the current user, used
by the InternetAddress method getLocalAddress.
I know from experience that the envelope sender address can be set with Custom property mail.smtp.from. See https://javaee.github.io/javamail/docs/api/com/sun/mail/smtp/package-summary.html
mail.smtp.from Email address to use for SMTP MAIL command. This sets the envelope
return address. Defaults to msg.getFrom() or
InternetAddress.getLocalAddress(). NOTE: mail.smtp.user was previously
used for this.
I am trying to send an email, using the MATLAB sendmail function. I have been following the instructions of the sendmail function analysis in Mathworks on this link: https://uk.mathworks.com/help/matlab/import_export/sending-email.html
The code which I used on the command window is the following:
setpref ('Internet','E_mail','myemailaddress#gmail.com');
setpref ('Internet','SMTP_Server','smtp.gmail.com') ;
sendmail('emailofreceiver#gmail.com','texttobesent') ;
The message that I am getting after running those commands is the following:
Error using sendmail (line 169)
Could not connect to SMTP host: smtp.gmail.com, port: 25;
Connection timed out: connect
From what I understand I must change the arguments inside the second setpref function that I call, though I am not sure what exactly to include it them, based on the the gmail smtp port that is returned. Any help would be very much appreciated! Thank you in advance!
You may also need to set up something related to SSL. Try to add following besides SMTP_Username and SMTP_Password, and it should work for gmail:
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.fallback', 'false');
props.setProperty('mail.smtp.socketFactory.port', '465');
As #Xiangru Li said on his answer, setting up related to SSL is indeed needed. But that was not enough. Eventually, I had to change my google settings to turn on access for less secure apps. Information about doing this can be found in this link: https://support.google.com/accounts/answer/6010255?hl=en
So after doing this, the following code was successful and I managed to send an email with it:
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','E_mail','myemailaddress');
setpref('Internet','SMTP_Username','myusername');
setpref('Internet','SMTP_Password','mypassword');
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('emailofreceiver','testtobesent') ;
I'm getting hundreds/thousands of emails on my catch all address for my domain, with the subject "Returned mail: see transcript for details".
I am trying to catch these emails with spam assassin (SA) to mark them as spam, but the SA rule only works if I email a test email to my domain with that text in the subject. The actual spam mails are not marked... only the once I send myself as a test.
I have tried (in local.cf):
header LOCAL_SUBJECT_RETURNED_MAIL Subject =~ m/Returned mail/i
score LOCAL_SUBJECT_RETURNED_MAIL 10.0
header LOCAL_SUBJECT_RETURNED Subject =~ /\bReturned\b/i
score LOCAL_SUBJECT_RETURNED 10.0
Again... the rules are working, yet it looks like the spam emails come in without being scanned by spam assassin.
Does anyone have any idea on what I could try?
Things I've tried/done
I enabled php mail logging on my system, to ensure it's not being send through a script on my domain. Log is empty, so that's good.
The reason why spamassassin is not catching these emails (backscatter), is because they don't come through spamassasin, because they come from the mailer deamon inside my domain/webserver.
Test mail I send myself:
Received: from localhost by server.myprovider.net
with SpamAssassin (version 3.2.4);
Backscatter spam:
Return-Path:
Received: from localhost (localhost)
As you can see, it doesn't come through spamassassin, hence, no rules are triggered...
I try to send a simple Email via CakePHP's Email Component. I'm using following code from the cookbook documentation:
$this->Email->from = 'Irgendjemand <irgendjemand#example.com>';
$this->Email->to = 'Irgendjemand Anderes <irgendjemand.anderes#example.com>';
$this->Email->subject = 'Test';
$this->Email->send('Dies ist der Nachrichtenrumpf!');
The send()-method does only return a boolean value with the value false - but no error or warning occurs.
Does somebody have a solution for that?
Have you tried changing the delivery options? There are three options: mail, smtp and debug.
$this->Email->delivery = 'debug';
$this->Email->send('test message');
debug($this->Session->read('Message.email'));
You can debug with EMail. Set the delivery to debug and the email message will be set to Session.message:
if (Configure::read('debug') > 1) {
$this->Email->delivery = 'debug';
}
$ret = $this->Email->send();
if (Configure::read('debug') > 1) {
pr($this->Session->read('Message.email'));
}
Which OS are you on? If Windows, this note may be of interest:
Note: The Windows implementation of mail() differs in many ways from the Unix implementation.
...
As such, the to parameter should not be an address in the form of
"Something <someone#example.com>". The mail command may not parse this properly while talking with the MTA.
Secondly, it may just be the case that no mail server will accept outgoing mail from your local machine due to spam protection. I have often seen that the same mail() function will not work locally, but works fine once uploaded to a trustworthy server. You could try to use an authenticated mail relay in that case (SMTP).