codeigniter email class not sending mail with imap [duplicate] - php

I am developing a lightweight Gmail client for mobile phones, accessing Gmail by IMAP. I want to send a draft from the Drafts folder, but it has some attachments and I cannot download all of them to send it by SMTP.
Moving/copying it to "Sent Mail" does not send it, just moves it to that folder.
How can I send a Draft directly without fetching all the content and attachments from the client? Is there any IMAP command to do it?

IMAP is a mailbox protocol. It does not (natively) support sending mail, only accessing it. In order to send mail you must use SMTP. Its possible that there is an IMAP extension for sending mail, and its possible that Google Mail supports that extension, but I doubt it. Hence, if you want to send an email with attachments, you must actually have the full content of the message available to you to send.

IMAP was designed to receive email messages, not to send it. There is no IMAP command for sending email AFAIK. There is, however, at least one IMAP server which supports a special 'Outbox' folder. When you place the message into this folder it will be sent automatically.
Check Courier-IMAP documentation on Sending mail via an IMAP connection. Note, that this is a non standard method and I'm not aware of any other server which supports this.
There RFC 4468 which extends SMTP so it can fetch the mail content from the IMAP server, but I don't know about any working and widely used implementation.
Talking about gmail: sticking with SMTP is probably the safest way to go.

By the way, now that any modern mail client (including the webbased ones) supports a Sent folder, you typicaly have to use both SMTP and IMAP to send a single mail. And there's a race condition between sending the e-mail over SMTP and successfully saving the e-mail to the IMAP Sent folder. Using IMAP for sending e-mail is a way to avoid this race condition.

Sending email is a special feature of some imap servers. Its nothing in the imap protocol. You just copy your email into a special imap directory on the server and it sends them. I doubt that gmail supports this.

I sent an email to my own email address using IMAP using Python 3 to a gmail account. What is does is append a message to a mailbox. You need to utilize a handful of Python's native libraries. Also study this documentation for imaplib, this code is featured in the section Uploading Messages: To add a new message to a mailbox, construct a Message instance and pass it to the append() method, along with the timestamp for the message.
Then check your gmail inbox and you'll see the new message.
import imaplib
import time
import email.message
import imaplib_connect
new_message = email.message.Message()
new_message.set_unixfrom('name')
new_message['Subject'] = 'Test'
new_message['From'] = 'name#gmail.com'
new_message['To'] = 'name#gmail.com'
new_message.set_payload('This is an example message body.\n')
print(new_message)
with imaplib_connect.open_connection() as c:
c.append('INBOX', '',
imaplib.Time2Internaldate(time.time()),
str(new_message).encode('utf-8'))
# Show the headers for all messages in the mailbox
c.select('INBOX')
typ, [msg_ids] = c.search(None, 'ALL')
for num in msg_ids.split():
typ, msg_data = c.fetch(num, '(BODY.PEEK[HEADER])')
for response_part in msg_data:
if isinstance(response_part, tuple):
print('\n{}:'.format(num))
print(response_part[1])

Related

Mail send with PHP in outbox of a user?

I need to send mail from my PHP app, I wonder if I authenticate as a exchange user via PHPMailer, does my mails send from my app will be on the outbox in the MS Outlook of this user ?
Thanks
On most mail servers, no, this doesn't happen automatically, but you can do it yourself. The gmail example provided with PHPMailer shows how to save a sent message to your outbox using IMAP; it will be nearly identical for Outlook. Alternatively, BCC the original message to yourself and you'll receive a copy of everything you send, which provides a similar effect.

Can i use PHPMailer to send from my mail server?

I want to send message from my mail server, for example from. Can i use for that PHP Mailer class? And how STTP server checks the correctness of email? only checks that domain belongs one of his existing domains?
Sorry for bad english ))
Yes you can use phpmailer. You need to put in the smtp information provided by your hosting company in order to send the email

handling bounce email w/phpmailer

I have a webpage that sends out emails using phpmailer. I set the host to 'relay-hosting.secureserver.net' the mail->sender, mail->from and mail->addReplyTo all to the same address, which is the address that I want the bounced email notifications sent to. This email address in also with the same host and the smtp host. When I put in a bad email address I don't get a notification that is was not delivered. What am I doing wrong? Thanks
PHPmailer does not handle receiving emails. It's purely a library for allowing PHP to talk to an SMTP server for sending emails. It has absolutely no support whatsoever to act as a mail client (e.g. receiving).
PHPmailer has no way of knowing the email bounced, as the bounce occurs LONG after PHPmailer's handed the email off to the outgoing SMTP server. IN real world terms, PHPmailer takes your letter and walks down the block to drop it into a mailbox. The bounce occurs later, when the letter carrier brings the letter back with 'return to sender' stamped on it - PHPmailer is not involved in this at all.
Your options are:
1) Use PHP's imap functions to connect to an existing pop/imap server and retrieve emails that way
2) Use a .forward or similar redirect on the SMTP side to "send" incoming email to a PHP script.
I know this is an old and answered question, but for those who may find this post later with a similar problem you might be able to solve this by going to your smtp mail relay service. If for example you use jangosmtp there is an option in your jangosmtp control panel to either hard code the address to which bounce reports should be sent or to always send bounce reports to the From address.

To detect spam messages using imap php

I am retriving my mails using php imap function.
I am retriving all messages from server and i need to know how to detect messages which are spam in my received mails.
Question: How to Detect spam in emails received using imap php
Usually that is the job of your mail server admin, if you are him you will need to use a 3rd party software like SpamAssassin. The choise is up to you and your specific implementation of a mail server.

PHP - Specifying the SMTP server to send mail through

I am developing a simple webmail client for IMAP-based email services using PHP's IMAP library, and I was wondering if there was any way to specify the SMTP server to use when sending an outgoing message, so that the message will be placed in the user's Sent mailbox when they are logged into their IMAP account. I saw that their is an imap_mail() function however it looks from the docs like it is just basically an alias for the normal mail() function, or am I wrong in assumming that?
Why don't you use a full featured class for this function, like PHPMailer?
Saving a copy to the Sent Mail folder is a function of IMAP, and is completely unrelated to queuing the message for delivery via SMTP. I.e., your code will have to do both operations separately -- one does not imply the other.
I have noticed that Gmail adds a copy to the sent folder on its own. Is this common behavior for the big web-mail providers?

Categories