Sending mail via relay using PHP on Windows - windows

I am using PHPMailer (via SMTP) to send out emails via my websites. I am using a windows 2012 server as my mail server which is using Hmailserver. I am using Mailgun to relay my emails.
Things I have done:
I have setup and validated my mailgun settings.
I have tested sending and receiving emails via the server without the relay (works fine).
My dilemma:
At one stage I am going to have to state the relay information, such as the authentication or hostname. So far, i see two place where i can declare this - see below:
1) Specify via PHPMailer script:
$mail->IsSMTP();
$mail->host = "smtp.mailgun.org";
$mail->Username = "username";
$mail->Password = "password";
2) Specify in hmailserver admin (on the server):
http://puu.sh/cJLpk/c3d548981c.png
Which way do I do this if I want to relay all my emails?

Using your local mail server (hmailserver) as a relay will be faster (at least for your client scripts) and much more reliable. It should be configured to point at mailgun, as in your screen shot. Mailgun should provide you with credentials that you can use for authenticating the relay.
When you send with PHPMailer, you should configure it to point at localhost, like this:
$mail->IsSMTP();
$mail->Host = 'localhost';
$mail->Username = "username";
$mail->Password = "password";
(You may not need username and password for your local server). Though it may sound odd, using SMTP to localhost is often faster than calling a local sendmail binary (or using PHP's mail() function).
In your original code you had host instead of Host - PHP is case-senetive for property names, so that would have been failing if that was your real code.
That should be all there is to it.
The only other complication is if hmailserver is also sending messages that are not supposed to go through mailgun, in which case you will need to get further into your hmailserver config.

Related

Laravel not sending emails on Platform.sh to SendGrid

Im hosting a Laravel spark website on platform.sh. I have configured the environment variables within the platform.sh GUI to be what is suggested in their guides but for some reason SendGrid isn't picking up the emails.
I am using my SendGrid Log in details for username and password - I have also tried by using my API Keys.
There are no errors or anything and both SendGrid and Platform.sh are being useless saying they can't do or see anything, so im pretty lost as to where I go next. I have tried many various configuration options but none seem to have worked.
Here is the snippet of code to send the mailable in Laravel:
Mail::to($input['email'])->send(new BetaSignUp($referral, $referralFacebookUrl, $referralTwitterUrl));
Has anyone successfully got Laravel running on platform.sh, and sending emails via SMTP (SendGrid)
Thanks
EDIT
With the help of PSH i have run a python script they sent me to do a test on the container - this test was successful and I can see the email in SendGrid. Here is the test Script:
import smtplib
sender = 'info#smbstreams.live'
receivers = ['to-email#email.com']
message = """From: Deck Stream Team<info#smbstreams.live>
Reply-To: Deck Stream Team<deckstream#smbstreams.live>
To: To Person <to-email#email.com>
Subject: SMTP e-mail test
This is a test e-mail message.
"""
server = smtplib.SMTP_SSL('smtp.sendgrid.net', 465)
server.set_debuglevel(1)
server.login("****", "****")
server.sendmail(sender, receivers, message)
Have you follow this https://docs.platform.sh/development/email.html#enablingdisabling-email
Email support can be enabled/disabled per-environment. By default, it
is enabled on the master environment and disabled elsewhere. That can
be toggled in through the web UI or via the command line, like so:
platform environment:info enable_smtp true

Laravel mail on shared hosting

I've a form contact on my website and I want the form to be sent via email when submitted.
I've tried it in xampp and it's working fine.
On shared hosting, it does not work.
I'm using my own custom domain smtp.
Someone can explain me why it's not working ?
Your shared hosting probably blocks outgoing SMTP connections. Many hosting providers do that to prevent spam. You can try using a HTTP/WEB API instead of SMTP to send email.
Some email APIs like Flute Mail allow you to set up an HTTP API connection which can immediately forward the request through your "custom domain smtp" server. So you can keep using your custom domain email server, but get an API for it.
Otherwise you'll have to set up a Web API yourself with an open source tool like Postal.
In your laravel .env file if add following parameters mentioned below and create a e-mail on your shared hosting and add username, password and host of your hosting.
MAIL_DRIVER=smtp
MAIL_HOST=shared_host_name
MAIL_PORT=587
MAIL_USERNAME=mail#sharedhost.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
I suppose then it would work fine.

Spring mail MimeMessage has an incorrect "From " set

I am using spring mail to send an email via google's smptp server. I am setting my email templates "From" header but for some reason when I do receive the mail as a sender I get the owner of the smtp account. (which happens to be me again).
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message);
helper.setText(forgottenPassowrdMailTemplate.getText()
.replace("%firstName%", token.getUser().getFirstName())
.replace("%lastName%", token.getUser().getLastName())
.replace("%link%", url + token.getToken()), true);
helper.setTo(token.getUser().getEmail());
helper.setFrom(forgottenPassowrdMailTemplate.getFrom());
helper.setSubject(forgottenPassowrdMailTemplate.getSubject());
am I forgetting something ? I a am explicitly setting the "From" header
You are setting a from address that is different from the account's address. There are security measures by Google to avoid abuse, which could be fatal if you could just send with any arbitrary from address via Google's SMTP server. You need to link and verify your other account with the account you want to send the mail with. See here. Your original email address will still be available in the headers and visible to the receipient.
But why don't you just use the other accounts credentials (and mail server, if it is not a Google account)?

my issue by sending email with smtp server in joomla1.5?

background
I have a Joomla 1.5 site, for registering user in site to enable the email sending system's, configured the smtp server in joomla configuration.
my config is:
mailer:'smtp server'
smtp host:'smtp.gmail.com'
smtp user:'myuser#gmail.com'
smtp psw:'mypass'
smtp port:'465'
smtp authentication:'yes'
smtp security:'ssl'
I don't know becuase does not Work and it is worth noting that php mail function dosen't work!
This is Answer Of Question:
I'm use the free-hosting and the hosting company block the many php functions.
One of the php functions is fsockopen that socket to smtp server to connect them.
I hope this experiment help my friends.
uncomment "extension=php_openssl.dll" in your php.ini file
add exception for port 465
extension=php_openssl.dll
is used for windows hosting only, and most probably you will be using linux hosting so you don't need to worry about it.
I had a similar issue like yours and it turned out that the php function that I wrote in a script was not using smtp set in Joomla configuration, to confirm try using password reset or some other function that uses email from Joomla framework, and if you get that email successfully that would mean that your php email function is not using smtp.

Sending Email from Windows Azure Through BPOS

I'm trying to send an email via asp.net mvc2, and all works well on our companies mail server.
However, we're looking to switch to using our client's BPOS account. This works fine locally, but when deployed to azure, we're getting some timeout errors.
Can anybody confirm I have the following correct?
SmtpClient smtp = new SmtpClient("Smtp.mail.emea.microsoftonline.com");
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new NetworkCredential("BPOS-EMAIL", "BPOS-PASSWORD");
In addition, does anyone know why it works when run locally, but not when run on azure?
Are you running the web role in Full Trust? By default, SmtpClient is going to execute under ASP Medium trust. Under that model, Smtp is only allowed to communicate over port 25 in Azure.
If you need to use the SmtpClient.Port property, you'll need to have the role run under full trust.
That's achieved by setting the enableNativeCodeExecution attribute on the Web Role in the Service Definition.
<WebRole name="WebRole1" enableNativeCodeExecution="true">
Thats the only thing I can think it might be. If that's not it and you can post error logs, that may show more details as to the problem.

Resources