How to reply to the last email (IMAP4) in inbox?
Python IMAP4 how to reply to an email with a given UID or last email in Inbox
I have been able to login my gmail with IMAP4 and get the last UID , but I dont know how to reply to the last email in the inbox my python automation code:
self.mail = imaplib.IMAP4_SSL('imap.gmail.com')
self.mail.login(self.data["emailUsername"], self.data["emailPassword"])
self.mail.list()
self.mail.select("inbox")
subjectStr = '(HEADER Subject ' + """ + mySubject + """ + ')'
result, UIDemailsWithGivenSubject = self.mail.uid('search', None, subjectStr)
ids_string = UIDemailsWithGivenSubject[0].decode("utf-8")
ids_string_list = ids_string.split(" ")
self.lastEmailUid = ids_string_list[-1]
Now how do I respond to the last email or respond/reply with a given UID.
python email imap
add a comment |
Python IMAP4 how to reply to an email with a given UID or last email in Inbox
I have been able to login my gmail with IMAP4 and get the last UID , but I dont know how to reply to the last email in the inbox my python automation code:
self.mail = imaplib.IMAP4_SSL('imap.gmail.com')
self.mail.login(self.data["emailUsername"], self.data["emailPassword"])
self.mail.list()
self.mail.select("inbox")
subjectStr = '(HEADER Subject ' + """ + mySubject + """ + ')'
result, UIDemailsWithGivenSubject = self.mail.uid('search', None, subjectStr)
ids_string = UIDemailsWithGivenSubject[0].decode("utf-8")
ids_string_list = ids_string.split(" ")
self.lastEmailUid = ids_string_list[-1]
Now how do I respond to the last email or respond/reply with a given UID.
python email imap
add a comment |
Python IMAP4 how to reply to an email with a given UID or last email in Inbox
I have been able to login my gmail with IMAP4 and get the last UID , but I dont know how to reply to the last email in the inbox my python automation code:
self.mail = imaplib.IMAP4_SSL('imap.gmail.com')
self.mail.login(self.data["emailUsername"], self.data["emailPassword"])
self.mail.list()
self.mail.select("inbox")
subjectStr = '(HEADER Subject ' + """ + mySubject + """ + ')'
result, UIDemailsWithGivenSubject = self.mail.uid('search', None, subjectStr)
ids_string = UIDemailsWithGivenSubject[0].decode("utf-8")
ids_string_list = ids_string.split(" ")
self.lastEmailUid = ids_string_list[-1]
Now how do I respond to the last email or respond/reply with a given UID.
python email imap
Python IMAP4 how to reply to an email with a given UID or last email in Inbox
I have been able to login my gmail with IMAP4 and get the last UID , but I dont know how to reply to the last email in the inbox my python automation code:
self.mail = imaplib.IMAP4_SSL('imap.gmail.com')
self.mail.login(self.data["emailUsername"], self.data["emailPassword"])
self.mail.list()
self.mail.select("inbox")
subjectStr = '(HEADER Subject ' + """ + mySubject + """ + ')'
result, UIDemailsWithGivenSubject = self.mail.uid('search', None, subjectStr)
ids_string = UIDemailsWithGivenSubject[0].decode("utf-8")
ids_string_list = ids_string.split(" ")
self.lastEmailUid = ids_string_list[-1]
Now how do I respond to the last email or respond/reply with a given UID.
python email imap
python email imap
edited Jan 2 at 22:06


martineau
69.9k1092186
69.9k1092186
asked Jan 2 at 21:20
user3556956user3556956
1308
1308
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can search the selected mailbox like this:
res, data = self.mail.search(None, 'ALL')
Your data will then look something like this: [b'1 2 3 4 5 6 7 8 9 10 11 12']
where 12
is the UID for the latest email in the selected mailbox. You can now fetch this mail with
self.mail.fetch(data[0].split()[-1], '(RFC822)')
Explanation
IMAP4.search(charset, criterion[, ...])
returns a list of all emails in your current mailbox. They are typically orderd by date with the first one being the oldest.
Provide None
for the charset to search for any mail and the criterion is set to All
.
See Python imaplib documentation
data[0].split()[-1]
returns the last element ([-1]
) of your list of mail UIDs
Respond to mail
You are using the IMAP protocol to access a mailserver. IMAP stands for
Internet Message Access Protocol
It is intendet for message access, not to send mail. You need SMTP to send messages. Take a look at this question.
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013333%2fhow-to-reply-to-the-last-email-imap4-in-inbox%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can search the selected mailbox like this:
res, data = self.mail.search(None, 'ALL')
Your data will then look something like this: [b'1 2 3 4 5 6 7 8 9 10 11 12']
where 12
is the UID for the latest email in the selected mailbox. You can now fetch this mail with
self.mail.fetch(data[0].split()[-1], '(RFC822)')
Explanation
IMAP4.search(charset, criterion[, ...])
returns a list of all emails in your current mailbox. They are typically orderd by date with the first one being the oldest.
Provide None
for the charset to search for any mail and the criterion is set to All
.
See Python imaplib documentation
data[0].split()[-1]
returns the last element ([-1]
) of your list of mail UIDs
Respond to mail
You are using the IMAP protocol to access a mailserver. IMAP stands for
Internet Message Access Protocol
It is intendet for message access, not to send mail. You need SMTP to send messages. Take a look at this question.
add a comment |
You can search the selected mailbox like this:
res, data = self.mail.search(None, 'ALL')
Your data will then look something like this: [b'1 2 3 4 5 6 7 8 9 10 11 12']
where 12
is the UID for the latest email in the selected mailbox. You can now fetch this mail with
self.mail.fetch(data[0].split()[-1], '(RFC822)')
Explanation
IMAP4.search(charset, criterion[, ...])
returns a list of all emails in your current mailbox. They are typically orderd by date with the first one being the oldest.
Provide None
for the charset to search for any mail and the criterion is set to All
.
See Python imaplib documentation
data[0].split()[-1]
returns the last element ([-1]
) of your list of mail UIDs
Respond to mail
You are using the IMAP protocol to access a mailserver. IMAP stands for
Internet Message Access Protocol
It is intendet for message access, not to send mail. You need SMTP to send messages. Take a look at this question.
add a comment |
You can search the selected mailbox like this:
res, data = self.mail.search(None, 'ALL')
Your data will then look something like this: [b'1 2 3 4 5 6 7 8 9 10 11 12']
where 12
is the UID for the latest email in the selected mailbox. You can now fetch this mail with
self.mail.fetch(data[0].split()[-1], '(RFC822)')
Explanation
IMAP4.search(charset, criterion[, ...])
returns a list of all emails in your current mailbox. They are typically orderd by date with the first one being the oldest.
Provide None
for the charset to search for any mail and the criterion is set to All
.
See Python imaplib documentation
data[0].split()[-1]
returns the last element ([-1]
) of your list of mail UIDs
Respond to mail
You are using the IMAP protocol to access a mailserver. IMAP stands for
Internet Message Access Protocol
It is intendet for message access, not to send mail. You need SMTP to send messages. Take a look at this question.
You can search the selected mailbox like this:
res, data = self.mail.search(None, 'ALL')
Your data will then look something like this: [b'1 2 3 4 5 6 7 8 9 10 11 12']
where 12
is the UID for the latest email in the selected mailbox. You can now fetch this mail with
self.mail.fetch(data[0].split()[-1], '(RFC822)')
Explanation
IMAP4.search(charset, criterion[, ...])
returns a list of all emails in your current mailbox. They are typically orderd by date with the first one being the oldest.
Provide None
for the charset to search for any mail and the criterion is set to All
.
See Python imaplib documentation
data[0].split()[-1]
returns the last element ([-1]
) of your list of mail UIDs
Respond to mail
You are using the IMAP protocol to access a mailserver. IMAP stands for
Internet Message Access Protocol
It is intendet for message access, not to send mail. You need SMTP to send messages. Take a look at this question.
edited Jan 2 at 22:13
answered Jan 2 at 22:03
Jonas DrotleffJonas Drotleff
346215
346215
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54013333%2fhow-to-reply-to-the-last-email-imap4-in-inbox%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown