Jump to content

[MOD] TLS Email support - works with gmail smtp!


adamscybot

Recommended Posts

I was annoyed by not being able to use the gmail smtp because it uses TSL security. So I modified the PHPMailer class' to support it. Here are the instructions. This modification was completed on version 3.6.2 (should work on any version).

 

Backup includes/class.phpmailer.php

Backup includes/class.smtp.php

 

Open includes/class.phpmailer.php

 

Below:

 

$port = $this->Port;
     }

 

Place:

 


$strpos = strpos($host,"tls://");
  	if($strpos !== false) {
	$tls = true;
	$host = str_replace("tls://","",$host);
} else {
	$tls = false;
}

 

Below:

 

$this->smtp->Hello($this->ServerHostname());
       }

 

Place:

 


   if($tls == true) {
 	 if(!$this->smtp->StartTLS()) {
          $this->SetError($this->Lang("tls"));
          $this->smtp->Reset();
          $connection = false;
           }

     	   $this->smtp->Hello($hello);
      }

 

Save and upload.

 

Open includes/class.smtp.php

 

Below:

 

if($this->do_debug >= 2) {
     echo "SMTP -> FROM SERVER:" . $this->CRLF . $announce;
   }

   return true;
 }

 

Place:

 

/**
  * Initiate a TSL communication with the server.
  *
  * SMTP CODE 220 Ready to start TLS
  * SMTP CODE 501 Syntax error (no parameters allowed)
  * SMTP CODE 454 TLS not available due to temporary reason
  * @access public
  * @return bool success
  */
 public function StartTLS() {
   $this->error = null; # to avoid confusion

   if(!$this->connected()) {
     $this->error = array("error" => "Called StartTLS() without being connected");
     return false;
   }

   fputs($this->smtp_conn,"STARTTLS" . $extra . $this->CRLF);

   $rply = $this->get_lines();
   $code = substr($rply,0,3);

   if($this->do_debug >= 2) {
     echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
   }

   if($code != 220) {
     $this->error =
        array("error"     => "STARTTLS not accepted from server",
              "smtp_code" => $code,
              "smtp_msg"  => substr($rply,4));
     if($this->do_debug >= 1) {
       echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF;
     }
     return false;
   }

   //Begin encrypted connection
   if(!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
     return false;
   }

   return true;
 }

 

Save and upload.

 

Instructions for use:

 

To use a smtp server which requires tls security put "tls://" before the SMTP Host. The script will then attempt to connect with TLS security when an email is sent.

 

E.g. tls://smtp.gmail.com

 

Also, usually the port for TLS is different. Use 587 or 465 (587 works for me).

 

Hope this helps,

 

Adam

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

Worked fine (i just removed ":" after tls to avoid confusion with ports, because 3.7.1 smtp class files do a explode on the smtp server just before this part).

 

The problem is my pre-order contact form is sending me mails with my own address in "From:" field, then I can't reply the mails :shock:

 

Any tip on how to solve this?

 

Regards,

Renato

Link to comment
Share on other sites

I haven't yet tried the SMTP configuration for email, is it a better way to go? I do use Gmail...well, Google Apps, for all my correspondence which means nothing gets logged in WHMCS for me. Is this be big advantage, having everything logged in WHMCS?

 

I guess I'm just hesitant to test this out as everything seems to be working with the php mailer and my own Gmail Apps account.

Link to comment
Share on other sites

This response is specifically to answer benblee's question above:

 

Unless you specifically want to use the SMTP (Simple Mail Transfer Protocol) over POP3 to receive mail (There are no advantages in doing so) it is a useful but pretty much redundant feature of WHMCS. Indeed, SMTP raises more issues than it resolves. There is larger overhead in that SMTP uses more resources whilst also leaving copies of mail on the server. Frankly I think it just helps to make WHMCS a lot slower and the log files generated are a complete waste. Particularly if you use Google Apps which is an excellent way of managing client communications. I really cannot see why complicating life with SMTP pays off? Correct me if I am wrong.

 

Since mail is the subject, neither do I see much point in email piping. Again, it generates huge, redundant files and logs and I question its real value to clients because, whilst it appears to provide a minor convenience to them on the surface, there is a veiled trade-off. That is that clients then become much more remote from the whole Client Area with the attendant consequences of missing everything available there and being generally unaware of what is going on. I see no advantage to either client or host in those circumstances.

Edited by redrat
Link to comment
Share on other sites

I haven't yet tried the SMTP configuration for email, is it a better way to go? I do use Gmail...well, Google Apps, for all my correspondence which means nothing gets logged in WHMCS for me. Is this be big advantage, having everything logged in WHMCS?

 

I guess I'm just hesitant to test this out as everything seems to be working with the php mailer and my own Gmail Apps account.

 

I have to laugh here. Are you telling me you sell web and email hosting services, yet you dont even use them yourself to correspond with your clients?

Link to comment
Share on other sites

I have to laugh here. Are you telling me you sell web and email hosting services, yet you dont even use them yourself to correspond with your clients?
To be fair, he did not actually say any such thing now did he. I don't see why selling anything means that you have to use it yourself and, unless you do, it is such cause for merriment?

 

My mate sells Tampax but never personally inserts them. ;)

Link to comment
Share on other sites

I have to laugh here. Are you telling me you sell web and email hosting services, yet you dont even use them yourself to correspond with your clients?

 

Uuuummmm, yeah! I sell webhosting to the clients that I configure websites for...and to be perfectly honest, I can't see how sending them in the direction of software that is decades old when Google (a multi-billion dollar industry amongst themselves) has plenty of employees as smart as, or most probably more-so then myself, updating items such as their spam filter and email configuration options daily, as well as hosting email on their own servers lessening my own server load and increasing my customers productivity and ease of use,...is an option.

 

Did you get all that? If you aren't sure, you may want to read it again. Yeah, there are many benefits to outsourcing. Two heads are better than one...I'm a one man business...Google gives me a situation where thousands of heads are better than one and all I have to do is sign up.

 

Are you really smarter than everyone at Google combined? If so, and if you can configure an email system greater than theirs, I'm sure millions would be interested...in which case, why are you posting here?

Link to comment
Share on other sites

My mate sells Tampax but never personally inserts them. ;)

 

That is a great point to make.

 

Of all the posts here that involve someone asking what FTP is or why SSL is important, I catch some slack for asking about outsourcing email to a free offering by one of the most recognizable and sought after companies in the business. Go figure!

Link to comment
Share on other sites

benblee: I couldn't agree more. I have had such a great time since I started using Google Apps it would take some serious innovation before I changed back. The advantages are huge and that is precisely why more and more highly intelligent and capable web hosts have adopted that method.

 

I suspect that MACscr still lives in a cave and uses tin cans and string for a telephone. No offence MACscr. I trust your sense of humour extends to laughing at yourself when appropriate. ;)

Link to comment
Share on other sites

I use it to resell dedicated servers and consultant services.

 

The webserver where I'm hosted at the moment isn't allowing me to use php mail(), then I need to use SMTP. And a note: I'm using Google Apps also, like most of my customers those sell webhosting - which include webmail too. I see no problem with using something better than you can offer.

 

But back to the thread, anybody knows how to make this script send the mail with the correct "From" address - that inserted by visitor?

Link to comment
Share on other sites

- solved - (not this, but my php mail() problem! haha)

 

So are you running the php mail function instead? Or would you prefer SMTP and are still waiting a solution? I don't have the answer to your previous question but I am curious as to your server email preference.

Link to comment
Share on other sites

No matter. Both are fine for me. php mail() is so simple to use, and works fine.

 

However, the problem with SMTP seems to be the "From" header on the file class.smtp.php.

 

It puts the From that way: "From: My Customer <whmcsmail@mydomain.com>"

 

Then when I click "Reply" on mails, I'm replying myself... I should open the original mail source and find the Return-Path entry.

 

I'm just too busy to fix it, but I'll try soon.

Link to comment
Share on other sites

Like brasiweb

 

$this->smtp->Hello($this->ServerHostname());
       }

 

I cant find this line to edit

 

I'm currently using version 3.7.1, Please help me

 

Hi,

 

Didn't realise this thread of mine became active!

 

Use 3.7.2 then follow instructions. Or, replace your files with my pre-modified ones. Download here:

 

http://sws.vxcomputers.com/includes.zip

 

Im not sure if it will work with 3.7.1 but im pretty sure it should.

 

Adam

Link to comment
Share on other sites

Yes, it will. 3.7.1 > 3.7.2 didn't changed these files.

 

Adam,

 

please take a look to the mentioned on first page: the customer mail is being set as Return-Path address, but the From address is the WHMCS system mail address (this way the Reply function doesn't work on gmail or other webmails - we need to open the headers to find the customer's mail). - at least for pre-order contact form.

 

Regards,

Renato

Link to comment
Share on other sites

Yes, it will. 3.7.1 > 3.7.2 didn't changed these files.

 

Adam,

 

please take a look to the mentioned on first page: the customer mail is being set as Return-Path address, but the From address is the WHMCS system mail address (this way the Reply function doesn't work on gmail or other webmails - we need to open the headers to find the customer's mail). - at least for pre-order contact form.

 

Regards,

Renato

 

Hi,

 

I think this is related to the SMTP server re-writing these fields. I know Gmail does it:

 

http://groups.google.com/group/hosted-the-basics/browse_thread/thread/553f48f42aa01ba0

 

It appears to be a spam prevention thing.

 

"Some clarification: I set up Gmail for a client for SMTP access, and we discovered the following huge drawback: Gmail automatically rewrites the "from" line of any e-mail you send via their SMTP gateway to your Gmail address, and it overrides any Reply-To settings you may have in your e-mail software in favor of the one in Gmail's web interface. So while Gmail's SMTP access sure is handy, it's not a perfect solution for everybody."

 

Now this means you can not get round it. I own a google apps account so I can have whatever@mydomain.com that makes it so you can at least hide the fact your using gmail. However, this problem can not be solved with gmail SMTP servers and indeed others that do this (I expect many do).

 

I use WHMCS for Us --> Client emails anyway and have manually cut away the pre-order form in favour of direct email.

 

This may not suit some but there is no other way.

Link to comment
Share on other sites

There's no problem of customer see I use GMail. This is just a boring work to open headers and find the e-mail where I should reply to. The mail sent through the pre-order form is received by me, not by the customer. Since I get the correct e-mail on Return-Path and reply to the the customer, then we can share e-mails with no problems anymore.

 

But thanks for the info. Now I know it's not something "fixable" on this code itself, it's a general tricky trap Google made to us :)

Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...
  • 2 weeks later...
  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated