CakePHP Email changing from address on SMTP - email

I have this email config to send via SMTP through our Google Apps Business Account.
class EmailConfig {
public $default = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'myemail#mygmaildomain.com',
'password' => 'secret_password',
'transport' => 'Smtp'
);
}
When I send an email doing this:
$email = new CakeEmail('default');
$email->from('no-reply#mygmaildomain.com', 'My App');
$email->to(array('recipient#mygmaildomain.com' => 'Recipient Name'));
$email->subject('Test Email');
$email->emailFormat('html');
$email->send();
The email gets delivered, but it sends the mail from: myemail#mygmaildomain.com and not no-reply#mygmaildomain.com.
Is there another setting that I need to use or is this not possible?
EDIT:
I've tried the solution provided in the comment below, however it still doesn't make the email come from no-reply

When using Google's SMTP server, the from header is ignored.
$email->from('no-reply#mygmaildomain.com', 'My App'); //Ignored by Gmail
From DigitalOcean's tutorial How to use Google's SMTP server:
NOTE: Google automatically rewrites the From line of any email you send via its SMTP server to the default Send mail as email address in your Gmail or Google Apps email account Settings. You need to be aware of this nuance because it affects the presentation of your email, from the point of view of the recepient, and it may also affect the Reply-To setting of some programs.
For this to work, you have to modify your mail settings in your Google Apps control panel:
Workaround: In your Google email Settings, go to the Accounts tab/section and make "default" an account other than your Gmail/Google Apps account. This will cause Google's SMTP server to re-write the From field with whatever address you enabled as the default Send mail as address.

Related

TYPOP3 powermail: why email to receivers is not send?

I have a TYPO3 website v10 and using powermail forms.
The test mail in installtool is send good.
The mail to user is send good.
The mail to receivers is not send. This is very strange.
Here is my settings from localconf file:
'defaultMailFromAddress' => 'contact#company.gmbh',
'defaultMailFromName' => 'contact#company.gmbh',
'defaultMailReplyToAddress' => 'contact#company.gmbh',
'defaultMailReplyToName' => 'contact#company.gmbh',
'transport' => 'smtp',
'transport_sendmail_command' => '/usr/sbin/sendmail -t -i',
'transport_smtp_encrypt' => false,
'transport_smtp_password' => '123456789123456',
'transport_smtp_server' => 'smtp.office365.com',
'transport_smtp_username' => 'admin#company.gmbh',
Can you please give me some idea why is the email to receivers never works?
Things you should check:
what is the sender address of the mail which is sent to the receiver? You should avoid to use the email address from the form data as sender address because most mail servers check SPF records nowadays. Better use TypoScript to set a static sender address like info#company.gmbh or no-reply#company.gmbh. To increase comfort for the receiver you could set a reply-to address. See here for details how to do that.
is the subject really set? If it's empty no mail is sent.
To track problems further I suggest to use a local development environment like DDEV which provides Mailhog out of the box to intercept all mails which are sent from the webserver. This helps a lot to test mails.
If your receiver mail is sent as Bcc: you might have hit an incompatibility of symfony/mailer (which TYPO3 uses from v10+) used with sendmail -i -t (symfony/mailer issue).
You can work around it by using transport_sendmail_command = /usr/sbin/sendmail -bs.
This TYPO3 issue explains it, too.

Powermail doesn't send mail

I have installed powermail extension 4.4 on typo3 v7.6 project, the test mail is sending good, but when I fill the form on frontend and click submit, no e-mail is delivered/arrives.
I configured the form in backend with name, e-mail, and subject for both receiver and sender.
I have used different e-mail addresses too.
I have also tried to disable the spamshield from typoscript : spamshield._enable = 0.
I have added a defaultEmailAdress in the installtool config : [MAIL][defaultMailFromAddress] .
Does anybody have another idea?
Whats in your LocalConfiguration.php ?
'MAIL' => [
'transport' => 'sendmail',
'transport_sendmail_command' => '/usr/sbin/sendmail -t -i ',
should mostly work fine. But maybe you need to change transport to smtp or something else?
What really works good for me is the setup with Mailhog, to try Emails in Development.
I have fixed that, the problem was that i have used an different email adress in the plugin different from the adress in the smtp setting of installtool, this is was wrong, i have to use the same adress.

Do I need a user#mydomain.com email for sending emails using Mailgun?

I am currently using Mailgun for sending emails. I have verified my domain and entered all the records correctly.
I am using laravel which provides an easy way to use mailgun for sending emails.
I have given a MAIL_FROM_ADDRESS as a gmail address eg.
MAIL_FROM_ADDRESS=user#gmail.com
MAIL_TO_ADDRESS=myaccount#gmail.com
But this is not working at all. The Mailgun logs shows email is delivered but no email is received in my gmail inbox at eg. myaccount#gmail.com
So is it because my MAIL_FROM_ADDRESS is a gmail address and not a domain email address?
The way that I've always used mail gun is that when you are in your mailgun account and click on the domain. I use the Defualt SMTP Login (under Domain Information) and that is my MAIL_FROM_ADDRESS
Here is a snippet from my code that may or may not help you. In this example I'm using a blade template for the email.
try {
Mail::send('hostconfirmationemail', ['client' => $event->client,
'user' => $event->user],
function ($mail) use ($event) {
$mail->from('postmaster#yourdomain.com', 'Mail Room');
$mail->to($event->user->email)->subject('New Lead Seminar RSVP Confirmation');
});
} catch (\Exception $e) {
return $e->getMessage();
}

email sender with grails mail plugin

im trying to send email with mail plugin in grails with the gmail account.
The email is sent successfully but i have a problem with the sender of the email
In Config.groovy
grails {
mail {
host = "smtp.gmail.com"
port = 465
username = "myacount#gmail.com"
password = "mypassword"
props = ["mail.smtp.auth":"true",
"mail.smtp.socketFactory.port":"465",
"mail.smtp.socketFactory.class":"javax.net.ssl.SSLSocketFactory",
"mail.smtp.socketFactory.fallback":"false"]
}
}
Then from my app, i call
mailService.sendMail {
to "another#gmail.com"
from "sender#gmail.com"
subject sub
body message
}
The email is sent fine to another#gmail.com, but the sender is not the sender#gmail.com but the myaccount#gmail.com. Any advice?
You can't do this in on GMail. It forces you to use the "myaccount#gmail.com", you'll need to either use a local provide, another provider all together or accept "myaccount#gmail.com".
I believe this is done on purpose to prevent people from sending spam through Gmail.
There is actually a way to change the 'from' under certain conditions, see http://support.google.com/mail/bin/answer.py?hl=en&answer=22370
While not a direct answer to the question, in case anyone else lands here looking for a way to send a human readable sender address, you can do so by specifying it as such
from: "Sender Name"

cakephp emails not working

my problem is:
in the controller I have:
var $components = array('Email');
the method to send emails looks like this:
function send_emails() {
$this->Email->from = 'Somebody <somebody#example.com>';
$this->Email->to = 'Somebody Else <myspamplace#centrum.cz>';
$this->Email->subject = 'Test';
$this->Email->send('Hello message body!');
}
I am using Cake 1.3 and running it on localhost with Apache 2.2.11 and PHP5. Do you guys have any idea why it doesn't work?
When I put
$this->Email->delivery = 'debug';
in the code, it displays the email info and it seems like everything is ok.
Do you have any ideas what can be the reason why it doesn't send email?
If you're developing on a remote server, i.e. a hosting server, then that should work as it'll pick up the default email.
As you're not, you have to give the mail component some email capability. You can do this by, for example, feeding in your gmail (or whatever) smtp details, i.e. server, login, password.
/* SMTP Options for GMAIL */
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'auth' => true,
'host' => 'ssl://smtp.gmail.com',
'username'=>'your_username#gmail.com',
'password'=>'your_gmail_password',
);
/* Set delivery method */
$this->Email->delivery = 'smtp';
See http://book.cakephp.org/view/1290/Sending-A-Message-Using-SMTP
If you're not sure what credentials to use, look it up in your email provider's help or faq. Typically it can be found by searching for how to set up Outlook or Thunderbird.
Are you sending from a windows server? If so, have you properly setup your MTA in the php ini? Can you send mail using the mail() function?
If you are on windows and need an MTA, hMail is great for development, note that many hosts will reject mail from your local machine a spam so don't use on production without an MX record, domain keys etc.
You need an SMTP server to send email. If you are trying to send it from your localhost, two good alternatives are:
FreeSMTP: A Windows-based tool that lets your computer act like an SMTP Server
Gmail: You can use your Gmail address for testing purposes.
You need to follow the instructions to send email using CakePHP through SMTP. You could also modify your php.ini settings to reflect the new settings.
I had the same problem, I forgot to enable ssl on my xampp server, for that it is necessary just to add(or uncomment) extension=php_openssl.dll line in your php.ini file. Hope it helps.