Send email using inbound emials and Display email in my emails.

Hello

  1. i have created custom Api for Send email and create entry for email in module.
    it is sending email using default smtp and create entry in email
    but that emails not display in my mail in suite crm.
    my code is

require_once(‘include/SugarPHPMailer.php’);

$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();

include_once( ‘module/Notes/Note.php’ );
$note = new Note();
$where = “notes.id = ‘$file’”;
$attachments = $note->get_full_list("", $where, true);

$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
$mail->From = $from_email;
$mail->FromName = $from_name;
$mail->Subject = $subject;
$mail->Body = $body;

foreach ($attachments as $attachment) {
// Set the different fields for the attachments
$file_name = $attachment->filename;
$location = “upload/{$attachment->id}”;
$mime_type = $attachment->file_mime_type;

// Add attachment to email
$mail->AddAttachment($location, $file_name, ‘base64’, $mime_type);
}

$mail->prepForOutbound();
$arr = explode(",", $to);
foreach ($arr as $value) {
$mail->AddAddress($value);
}
$mail->Sender = $mail->From;
$originalEmail = new Email();
$originalEmail->retrieve($email_id);
$originalEmail->reply_to_status = 1;
$originalEmail->save();
if (!$mail->Send()) {
$GLOBALS[‘log’]->fatal(“ERROR: Mail sending failed!”);
}

there is no save email in my mails.

  1. We need to send emails using inbound email configuration.

Could you please provide us direction or suggestion for this functionality ?