11

Hello I am trying to get a website up and running. It is currently hosted on AWS, so I do not have my own smtp server running at this moment. So after reading a few articles, I have understood that we could used gmail as a smtp server.

I wanted to double check if what I read was right, I am going to use smart job board software, can I plug in the values provided by gmail and use that as an smtp server??

macha
  • 7,337
  • 19
  • 62
  • 84

5 Answers5

6

I successfully use the GMail SMTP server.

We do have a corporate GMail account, though I don't think that matters. A personal GMail account should suffice.

I do not have a PHP sample however the following configuration for ASP.Net should provide adequate guidance:

<mailSettings>
  <smtp from="me@gmail.com">
    <network enableSsl="true" host="smtp.gmail.com" port="587" userName="me@gmail.com" password="mypassword" />
  </smtp>
</mailSettings>

If someone has a suitable PHP sample, feel free to edit my answer or post your own.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • 2
    You realize that you gave him `web.config` ... and he is asking for php .. right? – Mihai Iorga Aug 30 '12 at 04:31
  • Settings translate easily to PHP. I don't have a PHP example. – Eric J. Aug 30 '12 at 04:46
  • Then you should not post an ASP example. – Mihai Iorga Aug 30 '12 at 04:49
  • 1
    @MihaiIorga: Why? The question is about whether GMail can be used as an SMTP server. Nothing in the question asks *how* to do that from PHP, ASP.Net or any other language. That is outside the scope of the question. – Eric J. Aug 30 '12 at 06:43
  • Downvoting the only correct answer doesn't really help find the best answer (the other answer names an incorrect port). – Eric J. Aug 30 '12 at 06:46
  • 1
    You can always look at tags to see what he needs answer for – Mihai Iorga Aug 30 '12 at 06:46
  • 1
    And btw, I didn't downvoted you yet. I was waiting for a PHP example – Mihai Iorga Aug 30 '12 at 06:47
  • 3
    @MihaiIorga: Please see the FAQ: *Above all, be honest. If you see misinformation, vote it down. Add comments indicating what, specifically, is wrong. Provide better answers of your own. Best of all — edit and improve the existing questions and answers!* My answer is not wrong (there is no misinformation). I do not have a PHP code sample, but I did provide accurate information. If you wish, provide your own answer or edit and improve mine. – Eric J. Aug 30 '12 at 06:50
6

Yes, Google allows connections through their SMTP and allows you to send emails from your GMail account.

There are a lot of PHP mail scripts that you can use. Some of the most popular SMTP senders are: PHPMailer (with an useful tutorial) and SWIFTMailer (and their tutorial).

The data you need to connect and send emails from their servers are your GMail account, your password, their SMTP server (in this case smtp.gmail.com) and port (in this case 465) also you have to make sure that emails are being sent over SSL.

A quick example of sending an email like that with PHPMailer:

<?php
    require("class.phpmailer.php");

    $mail = new PHPMailer();

    $mail->IsSMTP();  // telling the class to use SMTP
    $mail->SMTPAuth   = true; // SMTP authentication
    $mail->Host       = "smtp.gmail.com"; // SMTP server
    $mail->Port       = 465; // SMTP Port
    $mail->Username   = "john.doe@gmail.com"; // SMTP account username
    $mail->Password   = "your.password";        // SMTP account password

    $mail->SetFrom('john.doe@gmail.com', 'John Doe'); // FROM
    $mail->AddReplyTo('john.doe@gmail.com', 'John Doe'); // Reply TO

    $mail->AddAddress('jane.doe@gmail.com', 'Jane Doe'); // recipient email

    $mail->Subject    = "First SMTP Message"; // email subject
    $mail->Body       = "Hi! \n\n This is my first e-mail sent through Google SMTP using PHPMailer.";

    if(!$mail->Send()) {
      echo 'Message was not sent.';
      echo 'Mailer error: ' . $mail->ErrorInfo;
    } else {
      echo 'Message has been sent.';
    }
?>
offby1
  • 6,767
  • 30
  • 45
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
2

Authentication is required I believe, but I don't see why not. I won't do the research for you, but there are a couple things to look into:

  • Their SMTP server requires TLS encryption and is hosted on a non-standard port (995). You will need to ensure that AWS supports both of these options for SMTP outbound.
  • There is probably a cap on emails you can send before being marked as spam. You should research this and ensure it is not beyond your requirements.
regex
  • 3,585
  • 5
  • 31
  • 41
  • Port 995 is not a GMail port. SMTP is on port 465 or 587. IMAP is on port 993. http://support.google.com/mail/bin/answer.py?hl=en&answer=78799 – Eric J. Aug 30 '12 at 06:54
0

You can user PHPMailer class for this job. And you can easily configure the smtp.

An example of configuration

if (class_exists(@PHPMailer)) {
    $smtp_mail  = new PHPMailer();
    $smtp_mail->isSMTP();
    $smtp_mail->SMTPAuth   = true;                  // enable SMTP authentication
    $smtp_mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
    $smtp_mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $smtp_mail->Port       = 465;                   // set the SMTP port
    $smtp_mail->Username   = "info@example.com";  // GMAIL username
    $smtp_mail->Password   = "password";            // GMAIL password
    $smtp_mail->From       = "info@example.com";
    $smtp_mail->FromName   = "Name";
    $smtp_mail->AltBody    = "This is the body when user views in plain text format"; //Text Body
    $smtp_mail->WordWrap   = 50; // set word wrap
    $smtp_mail->AddReplyTo("info@example.com","Name");
    $smtp_mail->isHTML(true); // send as HTML
}
0

Although you can technically use Gmail as SMTP server, it is not recommended for larger websites. By time you may receive issues like "421 4.7.0 Temporary System Problem" or similar, is it was not designed to be used by an application, rather a single person.

Related issue for the error message above: Gmail SMTP error - Temporary block?

sajtdavid
  • 21
  • 1