1
votes

I am using swift mailer to send emails and imap_append function to copy the the message in sent folder. The IMAP folder settings work properly with Yahoo and Hotmail accounts.

When mails are sent using a Gmail account SMTP and IMAP configuration, two copies are stored in the sender's "Sent" folder.

This is the IMAP code I am using:

$imapHostString = $mailSettings['imapServer'];

$imapHostString .= ($mailSettings['imapServerPort'] == 143)
    ? ":143"
    : ":{$mailSettings['imapServerPort']}/imap/ssl/novalidate-cert";

$mbox = imap_open('{' . $imapHostString . '}INBOX', $mailSettings['username'], $password);

imap_append($mbox, '{' . $imapHostString . '}' . $mailSettings['sentDirectoryName'], $message->toString() . "\r\n");
imap_close($mbox);

Why this is happening? Are there any gmail settings to be done?

1
If it's gmail, don't append to the sent box.Max

1 Answers

0
votes

This happens because Gmail automatically copies messages sent through its SMTP server into the sender's "Sent mail" folder, while Yahoo and Hotmail don't and thus require you to copy the message manually.

Other than trying to detect when the SMTP server is a Google one, I'm not aware of any way to detect this situation. It would be nice if the SMTP server would tell you that it was going to do this, for example.