Post by vacker » Mon Nov 08, 2010 1:05 am

The same virus notification is received if the mail is sent by OC 1.4.8 as a standard order confirmation.
I guess that the problem is somewhere in the headers but I'm not an expert of SMTP.
If I send an HTML e-mail via my e-mail client (Mozilla) then it is not identified as a virus by the same ISP's spam filter, so there must be a minor bug in the Mail class of OC.

New member

Posts

Joined
Fri Jul 09, 2010 9:52 pm


Post by vacker » Sat Nov 20, 2010 4:35 am

I have tried both PHP Mail and SMTP protocols with the same result.

New member

Posts

Joined
Fri Jul 09, 2010 9:52 pm


Post by vacker » Sat Nov 20, 2010 5:14 am

The Mail class replacement posted by Daniel on 22nd January 2010 works fine for me. No virus notification comes with the e-mail and the content is displayed properly.

New member

Posts

Joined
Fri Jul 09, 2010 9:52 pm


Post by vacker » Sat Nov 20, 2010 5:31 am

I have compared the two mail classes and identified the difference that solved the problem in my case. I found that a single line had to be removed from the Mail class (system/library/mail.php) of OC 1.4.8.
The line that need to be removed is line 145:

Code: Select all

$message .= '--' . $boundary . '--' . $this->newline; 
This is the last line of message composition, I guess it was inserted to close the message part.
Once I removed this line the HTML e-mail passed the virus scanner.
Do not hesitate to check if it solves the problem in your case as well and give a feedback.

New member

Posts

Joined
Fri Jul 09, 2010 9:52 pm


Post by vacker » Sat Nov 20, 2010 8:16 am

Well, my friends let me allow to correct my proposal. Do not delete the previously quoted line 145 from the Mail class but replace it with the following one:

Code: Select all

$message .= $this->newline . '--' . $boundary . '--' . $this->newline;
Simple deletion would result ugly message display in Outlook and does not comply with MIME specification.
The only thing that was missing is an empty line before the closing boundary.
Any feedback is appreciated.

New member

Posts

Joined
Fri Jul 09, 2010 9:52 pm


Post by OSWorX » Sat Nov 20, 2010 3:17 pm

Generally the whole mail class is buggy - as stated several times in the past.
Too many problems with different mail clients and systems.

Your solution may work inside and with your system, but the next user may have more troubles (or others).

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by Daniel » Sun Nov 21, 2010 9:29 am

if its a virus notifaction problem then its not oc's fault.

i'm using the mail system like it should work. the order emails sent out have both html and plain text sent in one email.


I have not really had any problems in a long time about the mail system.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by vacker » Tue Nov 23, 2010 5:44 am

Daniel, I like OC, I think you did a really good job.

I just share my experience, which is the following: if you add an extra new line just before the closing boundary then virus notification disappears. The content of my test e-mails were exactly the same in both cases (with and without the new new line), so the virus scanner could not find other difference between them than the mentioned new line character. I can imagine that a more strict mail filter simply deletes the mail that does not contain an empty line before the closing boundary.

This is why I would be happy, if someone who had the problem with undelivered e-mails would also try to add the mentioned new line according to my previous post and check if it solves his/her problem.

I'm too lazy to read through the corresponding RFCs to check why the empty line is necessary but it seems there are systems, who require it.

New member

Posts

Joined
Fri Jul 09, 2010 9:52 pm


Post by vacker » Tue Dec 07, 2010 8:44 pm

I was working with the modified Mail class without using attachments (I used the class outside of OC) without problems. Now, when I tried it with OC I found that the old problem with virus notification still exists.
Finally, I managed to make the provider's mail filter server silent. I have carried out the following changes:
1. Within the HTML alternative block of the message I have created a multipart/related block that holds both the HTML and the attachments (shop logo).
2. I have replaced the fixed attachment content type (application/octetstream) with an attachment extension dependent image/... content type.

I guess these changes may solve the problem of undelivered notification e-mails in some cases.

In order to check if it works for you simply replace the content of your system/library/mail.php file with the followings:

Code: Select all

<?php
final class Mail {
	protected $to;
	protected $from;
	protected $sender;
	protected $subject;
	protected $text;
	protected $html;
	protected $attachments = array();
	public $protocol = 'mail';
	public $hostname;
	public $username;
	public $password;
	public $port = 25;
	public $timeout = 5;
	public $newline = "\n";
	public $crlf = "\r\n";
	public $verp = FALSE;
	public $parameter = '';
	
	public function setTo($to) {
		$this->to = $to;
	}
   
	public function setFrom($from) {
		$this->from = $from;
	}
	
	public function addheader($header, $value) {
		$this->headers[$header] = $value;
	}
	
	public function setSender($sender) {
		$this->sender = $sender;
	}
	
	public function setSubject($subject) {
		$this->subject = $subject;
	}
	
	public function setText($text) {
		$this->text = $text;
	}
	
	public function setHtml($html) {
		$this->html = $html;
	}
	
	public function addAttachment($file, $filename = '') {
		if (!$filename) {
			$filename = basename($file);
		}
	  
		$this->attachments[] = array(
			'filename' => $filename,
			'file'     => $file
		);
	}

	private function getContentTypeByExtension($file_name) {
		$ctype = 'application/octetstream';
		$fext = pathinfo($file_name, PATHINFO_EXTENSION);
		if       (strcasecmp($fext, 'png')==0) {
			$ctype = 'image/png; name="' . basename($file_name) . '"';
		} else if(strcasecmp($fext, 'jpg')==0) {
			$ctype = 'image/jpeg; name="' . basename($file_name) . '"';
		} else if(strcasecmp($fext, 'gif')==0) {
			$ctype = 'image/gif; name="' . basename($file_name) . '"';
		} else if(strcasecmp($fext, 'tif')==0 || strcasecmp($fext, 'tiff')==0) {
			$ctype = 'image/tiff; name="' . basename($file_name) . '"';
		}
		return $ctype;
	}
	
	private function importAttachments($att_boundary) {
		$message = '';
		foreach ($this->attachments as $attachment) {			
			if (file_exists($attachment['file'])) {

				$handle = fopen($attachment['file'], 'r');
				$content = fread($handle, filesize($attachment['file']));
		
				fclose($handle); 
		
				$message .= '--' . $att_boundary . $this->newline;
				$message .= 'Content-Type: '. $this->getContentTypeByExtension($attachment['file']) . $this->newline;   
				$message .= 'Content-Transfer-Encoding: base64' . $this->newline;
				$message .= 'Content-Disposition: attachment; filename="' . basename($attachment['filename']) . '"' . $this->newline;
				$message .= 'Content-ID: <' . basename($attachment['filename']) . '>' . $this->newline . $this->newline;
				$message .= chunk_split(base64_encode($content));
			} else {
				print 'Attachment not found: ' . $attachment['file'];
			}
		}
		return $message;
	}

	public function send() {   
		if (!$this->to) {
			exit('Error: E-Mail to required!');
		}
	
		if (!$this->from) {
			exit('Error: E-Mail from required!');
		}
	
		if (!$this->sender) {
			exit('Error: E-Mail sender required!');
		}
	
		if (!$this->subject) {
			exit('Error: E-Mail subject required!');
		}
	
		if ((!$this->text) && (!$this->html)) {
			exit('Error: E-Mail message required!');
		}
	
		if (is_array($this->to)) {
			$to = implode(',', $this->to);
		} else {
			$to = $this->to;
		}
	
		$boundary = '----=_NextPart_' . md5(time()); 
	
		$header = '';
	
		if ($this->protocol != 'mail') {
			$header .= 'To: ' . $to . $this->newline;
			$header .= 'Subject: ' . $this->subject . $this->newline;
		}
	
		$header .= 'From: ' . $this->sender . ' <' . $this->from . '>' . $this->newline;
		$header .= 'Reply-To: ' . $this->sender . '<' . $this->from . '>' . $this->newline;   
		$header .= 'Return-Path: ' . $this->from . $this->newline;
		$header .= 'X-Mailer: PHP/' . phpversion() . $this->newline; 
		$header .= 'MIME-Version: 1.0' . $this->newline;
		$header .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . $this->newline; 
	
		if (!$this->html) {
			$message  = '--' . $boundary . $this->newline; 
			$message .= 'Content-Type: text/plain; charset="utf-8"' . $this->newline;
			$message .= 'Content-Transfer-Encoding: 8bit' . $this->newline . $this->newline;
			$message .= $this->text . $this->newline;
			$message .= $this->importAttachments($boundary);
		} else {
			$message  = '--' . $boundary . $this->newline;
			$message .= 'Content-Type: multipart/alternative; boundary="' . $boundary . '_alt"' . $this->newline . $this->newline;
			$message .= '--' . $boundary . '_alt' . $this->newline;
			$message .= 'Content-Type: text/plain; charset="utf-8"' . $this->newline;
			$message .= 'Content-Transfer-Encoding: 8bit' . $this->newline;
		
			if ($this->text) {
				$message .= $this->text . $this->newline;
			} else {
				$message .= 'This is a HTML email and your email client software does not support HTML email!' . $this->newline;
			}   
		
			$message .= '--' . $boundary . '_alt' . $this->newline;
			$message .= 'Content-Type: multipart/related; boundary="' . $boundary . '_rel"' . $this->newline . $this->newline;
			$message .= '--' . $boundary . '_rel' . $this->newline;
			$message .= 'Content-Type: text/html; charset="utf-8"' . $this->newline;
			$message .= 'Content-Transfer-Encoding: 8bit' . $this->newline . $this->newline;
			$message .= $this->html . $this->newline;
			$message .= $this->importAttachments($boundary . '_rel');
			$message .= '--' . $boundary . '_rel--' . $this->newline . $this->newline;      
			$message .= '--' . $boundary . '_alt--' . $this->newline . $this->newline;      
		}

		$message .= '--' . $boundary . '--' . $this->newline;
		
		if ($this->protocol == 'mail') {
			ini_set('sendmail_from', $this->from);
	
			if ($this->parameter) {
				mail($to, $this->subject, $message, $header, $this->parameter);
			} else {
				mail($to, $this->subject, $message, $header);
			}
			
		} elseif ($this->protocol == 'smtp') {
			$handle = fsockopen($this->hostname, $this->port, $errno, $errstr, $this->timeout);   
	
			if (!$handle) {
				error_log('Error: ' . $errstr . ' (' . $errno . ')');
			} else {
				if (substr(PHP_OS, 0, 3) != 'WIN') {
					socket_set_timeout($handle, $this->timeout, 0);
				}
		
				while ($line = fgets($handle, 515)) {
					if (substr($line, 3, 1) == ' ') {
						break;
					}
				}
		
				if (substr($this->hostname, 0, 3) == 'tls') {
					fputs($handle, 'STARTTLS' . $this->crlf);
				
					while ($line = fgets($handle, 515)) {
						$reply .= $line;
					
						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}
		
					if (substr($reply, 0, 3) != 220) {
						error_log('Error: STARTTLS not accepted from server!');
					}               
				}
		
				if (!empty($this->username)  && !empty($this->password)) {
					fputs($handle, 'EHLO ' . getenv('SERVER_NAME') . $this->crlf);
				
					$reply = '';
				
					while ($line = fgets($handle, 515)) {
						$reply .= $line;
				
						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}
		
					if (substr($reply, 0, 3) != 250) {
						error_log('Error: EHLO not accepted from server!');
					}
		
					fputs($handle, 'AUTH LOGIN' . $this->crlf);
		
					$reply = '';
		
					while ($line = fgets($handle, 515)) {
						$reply .= $line;
					
						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}
		
					if (substr($reply, 0, 3) != 334) {
						error_log('Error: AUTH LOGIN not accepted from server!');
					}
		
					fputs($handle, base64_encode($this->username) . $this->crlf);
		
					$reply = '';
		
					while ($line = fgets($handle, 515)) {
						$reply .= $line;
						
						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}
		
					if (substr($reply, 0, 3) != 334) {
						error_log('Error: Username not accepted from server!');
					}            
		
					fputs($handle, base64_encode($this->password) . $this->crlf);
		
					$reply = '';
		
					while ($line = fgets($handle, 515)) {
						$reply .= $line;
					
						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}
		
					if (substr($reply, 0, 3) != 235) {
						error_log('Error: Password not accepted from server!');               
					}   
				} else {
					fputs($handle, 'HELO ' . getenv('SERVER_NAME') . $this->crlf);
		
					$reply = '';
		
					while ($line = fgets($handle, 515)) {
						$reply .= $line;
					
						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}
		
					if (substr($reply, 0, 3) != 250) {
						error_log('Error: HELO not accepted from server!');
					}            
				}
				
				if ($this->verp) {
					fputs($handle, 'MAIL FROM: <' . $this->from . '>XVERP' . $this->crlf);
				} else {
					fputs($handle, 'MAIL FROM: <' . $this->from . '>' . $this->crlf);
				}
				
				$reply = '';
				
				while ($line = fgets($handle, 515)) {
					$reply .= $line;
				
					if (substr($line, 3, 1) == ' ') {
						break;
					}
				}
		
				if (substr($reply, 0, 3) != 250) {
					error_log('Error: MAIL FROM not accepted from server!');
				}
		
				if (!is_array($this->to)) {
					fputs($handle, 'RCPT TO: <' . $this->to . '>' . $this->crlf);
				
					$reply = '';
				
					while ($line = fgets($handle, 515)) {
						$reply .= $line;
				
						if (substr($line, 3, 1) == ' ') {
							break;
						}
					}
		
					if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) {
						error_log('Error: RCPT TO not accepted from server!');
					}         
				} else {
					foreach ($this->to as $recipient) {
						fputs($handle, 'RCPT TO: <' . $recipient . '>' . $this->crlf);
		
						$reply = '';
		
						while ($line = fgets($handle, 515)) {
							$reply .= $line;
							
							if (substr($line, 3, 1) == ' ') {
								break;
							}
						}
		
						if ((substr($reply, 0, 3) != 250) && (substr($reply, 0, 3) != 251)) {
							error_log('Error: RCPT TO not accepted from server!');
						}                  
					}
				}
				
				fputs($handle, 'DATA' . $this->crlf);
				
				$reply = '';
					
				while ($line = fgets($handle, 515)) {
					$reply .= $line;
					
					if (substr($line, 3, 1) == ' ') {
						break;
					}
				}
			
				if (substr($reply, 0, 3) != 354) {
					error_log('Error: DATA not accepted from server!');
				}
			
				fputs($handle, $header . $message . $this->crlf);
				fputs($handle, '.' . $this->crlf);
			
				$reply = '';
			
				while ($line = fgets($handle, 515)) {
					$reply .= $line;
				
					if (substr($line, 3, 1) == ' ') { 
						break;
					}
				}
			
				if (substr($reply, 0, 3) != 250) {
					error_log('Error: DATA not accepted from server!');
				}
			
				fputs($handle, 'QUIT' . $this->crlf);
				
				$reply = '';
				
				while ($line = fgets($handle, 515)) {
					$reply .= $line;
				
					if (substr($line, 3, 1) == ' ') {
						break;
					}
				}
			
				if (substr($reply, 0, 3) != 221) {
					error_log('Error: QUIT not accepted from server!');
				}         
			
				fclose($handle);
			}
		}
	}
}
?>
Note: I'm using OC 1.4.8 and the code above solved my problems at least for the moment.
Please, let me know if it helped.

New member

Posts

Joined
Fri Jul 09, 2010 9:52 pm


Post by anno78 » Wed Dec 08, 2010 7:01 am

ERROR:

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /customers/------.it/-------.it/httpd.www/system/library/mail.php:406) in /customers/--------.it/---------.it/httpd.www/system/library/session.php on line 11

Newbie

Posts

Joined
Tue Nov 16, 2010 11:22 pm

Post by OSWorX » Wed Dec 08, 2010 7:15 am

Than you made an error while copying the posted code.
The script is exactly 406 lines long - the error code means there is something wrong.
Check your error log, there you should see the corrct line and error message.

Custom Development | Individuelle Entwicklung | Support & Bugfixes

Image Image Image


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by iqubalsingh » Tue Apr 17, 2012 2:20 am

I am getting this error can you help me out...I am using open cart 1.5.2
Notice: Error: RCPT TO not accepted from server! in /home/www/xxxxxxxxxx/system/library/mail.php on line 308

Newbie

Posts

Joined
Sun Mar 04, 2012 2:50 am

Post by jasperlee88 » Wed Apr 18, 2012 10:19 pm

iqubalsingh wrote:I am getting this error can you help me out...I am using open cart 1.5.2
Notice: Error: RCPT TO not accepted from server! in /home/www/xxxxxxxxxx/system/library/mail.php on line 308

i'm having the same issue as well. anyone got any idea what is this regarding? i've try searching online but to avail.

Newbie

Posts

Joined
Sun Apr 01, 2012 10:17 pm

Post by jasperlee88 » Wed Apr 18, 2012 10:52 pm

jasperlee88 wrote:
iqubalsingh wrote:I am getting this error can you help me out...I am using open cart 1.5.2
Notice: Error: RCPT TO not accepted from server! in /home/www/xxxxxxxxxx/system/library/mail.php on line 308

i'm having the same issue as well. anyone got any idea what is this regarding? i've try searching online but to avail.

okie. issue solve. i just change the store setting email(rather then using gmail) to my domain email and that settle it.

Newbie

Posts

Joined
Sun Apr 01, 2012 10:17 pm
Who is online

Users browsing this forum: No registered users and 3 guests