I cannot send mail with SwiftMailer or PHPMailer from Localhost using gmail - email

I have recently been unable to send out mails through php on localhost. I use PHPMailer and SwiftMailer in different parts of the application.
With SwiftMailer I get this:
Connection could not be established with host smtp.gmail.com [ #0]
With PHPMailer, the message is:
SMTP Error: Could not connect to SMTP host.
My settings on SwiftMailer look like this:
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername(APP_GMAIL_EMAIL)
->setPassword(APP_GMAIL_PWD);
I have gone through several threads here at SO and elsewhere, and tried many 'fixes' but the error messages remain the same. Some "solutions" I've tried are:
Enable OpenSSL inphp.ini (It was previously off)
Change smtp.gmail.com to smtp.googlemail.com
Replace smtp.gmail.com with certain gmail IP addresses
Replace smtp.gmail.com with gethostbyname('smtp.gmail.com')
Add ->setSourceIp('0.0.0.0') to the instantiation code above, after setUsername and setPassword
This code was previously working, and I'm not sure what could have broken the function. As part of troubleshooting, I have just confirmed that a similar code on Linux shared hosting is emailing satisfactorily, suggesting that the problem is somehow from my environment. Thus, I even tried different sources of internet access, in case it's an ISP thing.
How can I crack this nut?

I have been able to overcome the problem, at least with SwiftMailer. The solution must have arisen after my PHP upgrade from 5.2.5 to 5.6, which is the version I have currently. The insight came from this page:
https://github.com/swiftmailer/swiftmailer/issues/544
If you are using PHP 5.6, the error does occur because of the "SSL
context options" used for the stream context in swiftmailer. IN PHP
5.6 verify_peer and verify_peer_name the default was set to TRUE, so PHP checks the SSL certificate. It is currently not possible to
disable it in swiftmailer using some options.
You could disable the SSL check by modifying the function
"_establishSocketConnection" in StreamBuffer.php. Add these lines
before stream_socket_client command:
$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;
It would be great if these options could be set without hacking the
code.
Thanks to https://stackoverflow.com/a/29448735/2554788 who first pointed me to the said post.
By the way, the path to StreamBuffer.php is:
\lib\classes\Swift\Transport
A word of warning though: this solution is based on hacking the code inside a class, and will probably fail, say, after upgrading SwiftMailer versions (in which case you'd need to go back and hack the code again).
Perhaps, more current versions of SwiftMailer have put their acts together in PHP 5.6 (I use SwiftMailer 5.1 currently). I intend to try an upgrade ASAP, hoping there has been an elegant fix for this issue.

Related

Perl SMTP auth fails when password is passed via variable

I have several hundred Perl scripts that send email via gmail SMTP. All are, and have been working fine for a couple of years with the gmail password hard-coded.
To simplify password changes (and for security), I want to move the password to an env var, and pull that into the perl scripts. I am using the code below.
my $smtp = Net::SMTP::SSL->new('smtp.gmail.com', Port => 465);
my $passwd = $ENV{'PASSWD'}; # I added this line
$smtp->auth('email#gmail.com', $passwd); # I replaced 'theHardCodedPassWord' with $passwd
The same method works in a non-smtp scenario -- I pull info from an env var and use it.
What am I doing wrong?
Two obvious debugging approaches:
Print the values of $ENV{PASSWD} and $passwd before the call to auth().
Turn on debug output in the Net::SMTP::SSL object (add Debug => 1 to the call to new()).
A few other points:
The documentation for Net::SMTP::SSL is pretty clear that the module is deprecated and should no longer be used. It says that Net::SMTP now has built-in support for SSL connections.
Net::SMTP seems to be a rather low-level approach to this problem. Have you considered Email::Send::Gmail? I've even had success sending email through GMail with Email::Sender::Simple.
I know that GMail recently hardened their security around using their SMTP servers from external apps. There's more information about this change on the Google support site.

duplicate imap uid validities with mbsync

I am using mbsync to get imap mail from my university server and then dovecot locally to serve it to gnus/emacs. This works fine on one desktop machine, and one laptop, but a second laptop creates duplicate UIDs everytime I use it to access my mail. As I have the exact same set-up (to the best of my knowledge) on all three machines I am a bit baffled as to the source of this error. Does this ring any bells for anyone? Is there some sort of hidden or temp file that might be the source of such a problem that I could look for? Any guidance is appreciated.
mbsync version = 1.2.0
emacs = 24.5.50.1
dovecot 2.2.18
gnus 5.13
P.S. A great guide to fix these problems once they occur is this blog post here: http://tiborsimko.org/mbsync-duplicate-uid.html

How can I use Mandrill App as system message mailer on Parallels Panel?

Currently I have my CentOS system set up with Parallels Panel and have my mailing system working nicely. But I'd prefer to have my system messages to be mailed using Mandrill App (MailChimp guys).
I have it working now with a kind of a mixed setup. Simple, though working. But now I get an error in my mail logs saying the following:
Jan 4 10:41:11 shinjuku postfix/smtp[29469]: certificate verification failed for smtp.mandrillapp.com[46.137.69.113]:25: untrusted issuer /C=ZA/ST=Western Cape/L=Cape Town/O=Thawte Consulting cc/OU=Certification Services Division/CN=Thawte Premium Server CA/emailAddress=premium-server#thawte.com`
After this I've tried configuring the smtp_tls_CApath and smtpd_tls_CApath to point to /etc/ssl/certs, but still no luck on this part.
Does someone have an idea on how I can get this working to have ALL system messages to be sent using Mandrill, instead of built-in config?
Mark, for CentOS try this for your CAPath/CAfile
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt

emails from localhost using mocksmtp

I have been trying to setup email on my local machine. After some advice that it is a rather involved thing to set up, I started to look around for a solution to my problem and came across an app called mocksmtp. I have followed this tutorial to set it up. But i'm getting errors.
of
send-mail: warning: valid_hostname: invalid character 64(decimal): my.email#address.com
send-mail: fatal: file /etc/postfix/main.cf: parameter myhostname: bad parameter value: my.email#address.com
Looking at this page I believe the problem is with /etc/postfix/main.cf
myhostname = my.email#address.com
but what value should I change the email address to to make this work? I have tried a few option but nothing has worked for me and in that post the only problem was a period at the end.
The tutorial is a valid and helpful page and would have worked perfectly had telnet localhost 1025 been enabled. Enabling telnet got it working. To do this telnet localhost 1025 worked for me
Looks like you're trying to enter an entire email in a parameter meant only for a host name. You should only have address.com, not my.email#address.com. It's not for a full email. You're setting this up as a server, to catch everything for a host, not just one particular email.

Squirrelmail autoforwarding incoming mails

I want to make squirrelmail automatically forward every email that I receive without having to login and do it myself. I have have found 2 plugins from the site but none of them seem to be working (autoresponder, local_autorespond_forward)
I tried to do that by myself straight from the code but the messages are decoded.I am new to squirrelmail so I would like some help please. It is installed in a ubuntu server.
This is the problem i get with autoresponder
There was a problem connecting to your FTP server: "cannot log in to localhost". Please contact your support department.
Local_autorespond_forward plugin does not show any option when i go change its properties from the options.
Thanks