Using IBM i SMTP Client to relay email to GMail

Any IBM i topic that does not fit in another forum
Post Reply
gio.cot
Posts: 6
Joined: Sat May 28, 2022 9:08 pm

Using IBM i SMTP Client to relay email to GMail

Post by gio.cot »

Hi all
we have an IBM i that run V7r1, and we would need to using to as SMTP Client to relay mail to Gmail; is there any way to do that with open source program ? i found some discussion in the web, but i'm not been able to understand if with V7R1 is possible to do that or not.
any suggestion or comments is welcome
Thanks in advance
Gio
Scott Klement
Site Admin
Posts: 288
Joined: Sun Jul 04, 2021 5:12 am

Re: Using IBM i SMTP Client to relay email to GMail

Post by Scott Klement »

What do you mean by 'relay to gmail'?

Do you mean that Google is letting you use one of their servers as an outgoing SMTP server?

Or do you mean you have your own internal network, smtp, and so forth, and you want to send mail that can be sent through to Google Mail? (This, actually, doesn't require any special setup -- if it's not working, you have the mail set up wrong, or your provider does.)

Provide more detail, please.
jonboy49
Posts: 80
Joined: Wed Jul 28, 2021 8:18 pm

Re: Using IBM i SMTP Client to relay email to GMail

Post by jonboy49 »

We use PHP to send emails via a gmail SMTP server and have been doing so for a number of years. It works fine but did take some playing around with to get it right initially.
gio.cot
Posts: 6
Joined: Sat May 28, 2022 9:08 pm

Re: Using IBM i SMTP Client to relay email to GMail

Post by gio.cot »

Hi Scott
i mean this :
Scott Klement wrote: Wed Aug 10, 2022 9:23 pm Do you mean that Google is letting you use one of their servers as an outgoing SMTP server?
Thanks in advance
Scott Klement
Site Admin
Posts: 288
Joined: Sun Jul 04, 2021 5:12 am

Re: Using IBM i SMTP Client to relay email to GMail

Post by Scott Klement »

I have not used one of Google's SMTP servers for outgoing mail. What are their requirements?
jonboy49
Posts: 80
Joined: Wed Jul 28, 2021 8:18 pm

Re: Using IBM i SMTP Client to relay email to GMail

Post by jonboy49 »

We use PHPMailer. I'll try to dig out the script we are using which should remind me of the requirements.
jonboy49
Posts: 80
Joined: Wed Jul 28, 2021 8:18 pm

Re: Using IBM i SMTP Client to relay email to GMail

Post by jonboy49 »

This is just part of the script - as far as I can see other than having to authenticate ourselves there's nothing really special there.

Code: Select all

require 'PHPMailerAutoload.php';

// Create a new PHPMailer instance
$mail = new PHPMailer;
 
// Set PHPMailer to use the SMTP transport
$mail->isSMTP();
 
// Set debug to verbose
//$mail->SMTPDebug = 2; 
//$mail->Debugoutput = 'html';
 
// Set host
$mail->SMTPAuth   = true;
$mail->Host = 'tls://smtp.gmail.com:587';

$mail->Username   = 'xxx@systemideveloper.com'; // SMTP account username
$mail->Password   = "yyyyyyyyyyy";        // SMTP account password

// Set who the message is to be sent from
$mail->setFrom('ABC@systemideveloper.com'');
$mail->Subject = "$company - Promotion Code for RPG & DB2 Summit in Chicago";

// Set who the message is to be sent to 
$mail->addAddress($email, $contact);
$mail->addCC('AnyCCPaeerson@systemideveloper.com', 'CC Person');
 
// Set the body and alt text
$mail->msgHTML( $html1 . $html2 ); 
$mail->AltBody = $text1 . $text2 ;

// send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo . "<br>";
 } else {
   echo "Message to: " . $contact . " with email: " . $email . " - sent!<br>";
 }

$mail->clearAllRecipients();
We may have had to make an additional entry in our DNS records but I don't recall the details. It was all spelt our by gmail.

Hope this helps.
Scott Klement
Site Admin
Posts: 288
Joined: Sun Jul 04, 2021 5:12 am

Re: Using IBM i SMTP Client to relay email to GMail

Post by Scott Klement »

Ok, so the requirements appear to be support for STARTTLS on port 587 and SASL with your login.

Will Jon's PHP option work for you?

In Node.js you could use Nodemailer, that should work fine.
gio.cot
Posts: 6
Joined: Sat May 28, 2022 9:08 pm

Re: Using IBM i SMTP Client to relay email to GMail

Post by gio.cot »

Scott and jonboy many thanks
unfortunatly i don't know PHP .. so it is hard for me follow the jonboy example; i tried to search for Nodemailer and i found Scott document at https://www.scottklement.com/presentati ... BM%20i.pdf. question for Scott: if i follow your example "Example, Node Mailer" , also if i know NodeJs just a little, do you think i will able to success on sending mail via Gmail ? are there in the web other example (for IBM i) that i can follow ?
Thanks in advance
Gio
Scott Klement
Site Admin
Posts: 288
Joined: Sun Jul 04, 2021 5:12 am

Re: Using IBM i SMTP Client to relay email to GMail

Post by Scott Klement »

There isn't anything "IBM i" related about your question. Open source solutions such as PHP or Node.js work the same on all platforms. (The same is true for Python, Java, Ruby, and so forth.)

I've already mentioned that I have not set up outgoing mail through Gmail.

So I went to Google and searched "nodemailer gmail" and immediately found this:
https://nodemailer.com/usage/using-gmail/
and this
https://mailtrap.io/blog/nodemailer-gmail/

I don't know the answer to your question, and Jon knows how to do it with PHP and has shown you that solution. You can easily find other solutions by searching for it.
Post Reply