diff --git a/modules/Emails/models/Record.php b/modules/Emails/models/Record.php
index 11fe808dd6baa4a3c89b53681bc5a6a1d45212f9..d92abdf56dad8b1ac73f9d4bb183ef3ee6d1da14 100644
--- a/modules/Emails/models/Record.php
+++ b/modules/Emails/models/Record.php
@@ -182,7 +182,7 @@ class Emails_Record_Model extends Vtiger_Record_Model {
             //Adding attachments to mail
             if(is_array($attachments)) {
                 foreach($attachments as $attachment) {
-                    $fileNameWithPath = $rootDirectory.$attachment['path'].$attachment['fileid']."_".$attachment['storedname'];
+                    $fileNameWithPath = $rootDirectory.$attachment['filenamewithpath'];
                     if(is_file($fileNameWithPath)) {
                         $mailer->AddAttachment($fileNameWithPath, $attachment['attachment']);
                     }
@@ -277,12 +277,24 @@ class Emails_Record_Model extends Vtiger_Record_Model {
 		$attachmentsList = array();
 		if($numOfRows) {
 			for($i=0; $i<$numOfRows; $i++) {
-				$attachmentsList[$i]['fileid'] = $db->query_result($attachmentRes, $i, 'attachmentsid');
-				$attachmentsList[$i]['attachment'] = decode_html($db->query_result($attachmentRes, $i, 'name'));
-                $attachmentsList[$i]['storedname'] = decode_html($db->query_result($attachmentRes, $i, 'storedname'));
-				$path = $db->query_result($attachmentRes, $i, 'path');
+                                $attachmentId = $db->query_result($attachmentRes, $i, 'attachmentsid');
+                                $rawFileName = $db->query_result($attachmentRes, $i, 'name');
+                                $storedName = $db->query_result($attachmentRes, $i, 'storedname');
+                                $path = $db->query_result($attachmentRes, $i, 'path');
+                                if($storedName) { 
+                                    $filename = $storedName;
+                                } else {
+                                    $filename = $rawFileName;
+                                }
+                                $attachmentsList[$i]['attachment'] = decode_html($rawFileName);
+                                $attachmentsList[$i]['fileid'] = $attachmentId;
+                                $attachmentsList[$i]['storedname'] = decode_html($storedName);
 				$attachmentsList[$i]['path'] = $path;
-				$attachmentsList[$i]['size'] = filesize($path.$attachmentsList[$i]['fileid'].'_'.$attachmentsList[$i]['storedname']);
+                                $saved_filename = $attachmentId."_".$filename;
+                                $filenamewithpath = $path.$saved_filename;
+                                $filesize = filesize($filenamewithpath);
+                                $attachmentsList[$i]['filenamewithpath'] = $filenamewithpath;
+				$attachmentsList[$i]['size'] = $filesize;
 				$attachmentsList[$i]['type'] = $db->query_result($attachmentRes, $i, 'type');
 				$attachmentsList[$i]['cid'] = $db->query_result($attachmentRes, $i, 'cid');
 			}
diff --git a/packages/vtiger/optional/ModComments.zip b/packages/vtiger/optional/ModComments.zip
index a1e37d05c84937d116fe22278de9d221f6e0ab05..bba05805eec71b34c2cd9dbd062a9fda1ef45be7 100644
Binary files a/packages/vtiger/optional/ModComments.zip and b/packages/vtiger/optional/ModComments.zip differ
diff --git a/pkg/vtiger/modules/ModComments/modules/ModComments/models/Record.php b/pkg/vtiger/modules/ModComments/modules/ModComments/models/Record.php
index 6d8807df47e7beeca77944c5be875adc1c410da6..6616d6a6e80c69fd01b85d7757c38aadebd4f667 100644
--- a/pkg/vtiger/modules/ModComments/modules/ModComments/models/Record.php
+++ b/pkg/vtiger/modules/ModComments/modules/ModComments/models/Record.php
@@ -412,14 +412,27 @@ class ModComments_Record_Model extends Vtiger_Record_Model {
 		$attachmentsList = array();
 		if($numOfRows) {
 			for($i=0; $i<$numOfRows; $i++) {
-				$attachmentsList[$i]['fileid'] = $db->query_result($attachmentRes, $i, 'attachmentsid');
-				$attachmentsList[$i]['attachment'] = decode_html($db->query_result($attachmentRes, $i, 'name'));
-				$path = $db->query_result($attachmentRes, $i, 'path');
+                                $attachmentId = $db->query_result($attachmentRes, $i, 'attachmentsid');
+                                $rawFileName = $db->query_result($attachmentRes, $i, 'name');
+                                $storedName = $db->query_result($attachmentRes, $i, 'storedname');
+                                $path = $db->query_result($attachmentRes, $i, 'path');
+                                if($storedName) { 
+                                    $filename = $storedName;
+                                } else {
+                                    $filename = $rawFileName;
+                                }
+                                $attachmentsList[$i]['attachment'] = decode_html($rawFileName);
+                                $attachmentsList[$i]['fileid'] = $attachmentId;
+                                $attachmentsList[$i]['storedname'] = decode_html($storedName);
 				$attachmentsList[$i]['path'] = $path;
-				$attachmentsList[$i]['size'] = filesize($path.$attachmentsList[$i]['fileid'].'_'.$attachmentsList[$i]['attachment']);
+                                $saved_filename = $attachmentId."_".$filename;
+                                $filenamewithpath = $path.$saved_filename;
+                                $filesize = filesize($filenamewithpath);
+                                $attachmentsList[$i]['filenamewithpath'] = $filenamewithpath;
+				$attachmentsList[$i]['size'] = $filesize;
 				$attachmentsList[$i]['type'] = $db->query_result($attachmentRes, $i, 'type');
 				$attachmentsList[$i]['cid'] = $db->query_result($attachmentRes, $i, 'cid');
-			}
+                        }
 		}
 		return $attachmentsList;
 	}