Python outlook win32 - error when getting every message from outlook returning “script”





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm writing a script for getting every image attachment from a sender in python 3.7 using pypiwin32.



import win32com.client
import click
import os
import logging

@click.command()
@click.option('-s', '--sender', 'sender', help="Sender's mail")
@click.option('-p', '--path', 'path', help="Save path")
def main(sender: str, path: str) -> None:

"""Save all attachments from a sender"""

# Get all messages from the inbox
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # 6 is the inbox folder
messages = inbox.Items
message = messages.GetFirst()

# Get all files from the path
files_list = os.listdir(path)

message_name_list =
message_counter = 0

while message:

print(message)

# Check if the message is from the sender
if message.SenderEmailAddress == sender:

# Check if the message name have been already used
if message not in message_name_list:

# Add message name to the list
message_name_list.append(message)

# Add one to msg counter
message_counter += 1

# Get the message date
mail_date = message.SentOn.date()

# Get all attachments from the message and get a count
attachments = message.Attachments
att_count = attachments.Count

# Check if the message have attachments
if att_count >= 1:

# Check if there is more than one attachments
if att_count > 1:

for att in range(att_count):

# Get attachments one by one
nb_att = att + 1
attachment = attachments.Item(nb_att)

# Set the filename for the attachment
filename = "img_" + str(mail_date) + "_" + str(message_counter) + "_" + str(nb_att) + ".jpg"

#check if file is already saved and save if not already saved
if filename not in files_list:
print (filename)
attachment.SaveAsFile(path + "\" + filename)

# Go to a next message
message = messages.GetNext()

else:
# Get the attachment
attachment = attachments.Item(1)

# Set the filename for the attachment
filename = 'img_' + str(mail_date) + "_" + str(message_counter) + '.jpg'

#check if file is already saved and save if not already saved
if filename not in files_list:
print (filename)
attachment.SaveAsFile(path + "\" + filename)

#Go to a next message
message = messages.GetNext()

if __name__ == "__main__":
main()


Normally in the terminal I should see the name of the mail and every saved attachments (called filename in my script). But actually I can only see that in the terminal:



script



script



script



script



And more others "script"



Someone know why no message are print and why "script" is print?
and how to fix that?










share|improve this question

























  • Maybe this link will help for you: stackoverflow.com/questions/45425251/…

    – Alina Li
    Nov 23 '18 at 8:20


















0















I'm writing a script for getting every image attachment from a sender in python 3.7 using pypiwin32.



import win32com.client
import click
import os
import logging

@click.command()
@click.option('-s', '--sender', 'sender', help="Sender's mail")
@click.option('-p', '--path', 'path', help="Save path")
def main(sender: str, path: str) -> None:

"""Save all attachments from a sender"""

# Get all messages from the inbox
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # 6 is the inbox folder
messages = inbox.Items
message = messages.GetFirst()

# Get all files from the path
files_list = os.listdir(path)

message_name_list =
message_counter = 0

while message:

print(message)

# Check if the message is from the sender
if message.SenderEmailAddress == sender:

# Check if the message name have been already used
if message not in message_name_list:

# Add message name to the list
message_name_list.append(message)

# Add one to msg counter
message_counter += 1

# Get the message date
mail_date = message.SentOn.date()

# Get all attachments from the message and get a count
attachments = message.Attachments
att_count = attachments.Count

# Check if the message have attachments
if att_count >= 1:

# Check if there is more than one attachments
if att_count > 1:

for att in range(att_count):

# Get attachments one by one
nb_att = att + 1
attachment = attachments.Item(nb_att)

# Set the filename for the attachment
filename = "img_" + str(mail_date) + "_" + str(message_counter) + "_" + str(nb_att) + ".jpg"

#check if file is already saved and save if not already saved
if filename not in files_list:
print (filename)
attachment.SaveAsFile(path + "\" + filename)

# Go to a next message
message = messages.GetNext()

else:
# Get the attachment
attachment = attachments.Item(1)

# Set the filename for the attachment
filename = 'img_' + str(mail_date) + "_" + str(message_counter) + '.jpg'

#check if file is already saved and save if not already saved
if filename not in files_list:
print (filename)
attachment.SaveAsFile(path + "\" + filename)

#Go to a next message
message = messages.GetNext()

if __name__ == "__main__":
main()


Normally in the terminal I should see the name of the mail and every saved attachments (called filename in my script). But actually I can only see that in the terminal:



script



script



script



script



And more others "script"



Someone know why no message are print and why "script" is print?
and how to fix that?










share|improve this question

























  • Maybe this link will help for you: stackoverflow.com/questions/45425251/…

    – Alina Li
    Nov 23 '18 at 8:20














0












0








0








I'm writing a script for getting every image attachment from a sender in python 3.7 using pypiwin32.



import win32com.client
import click
import os
import logging

@click.command()
@click.option('-s', '--sender', 'sender', help="Sender's mail")
@click.option('-p', '--path', 'path', help="Save path")
def main(sender: str, path: str) -> None:

"""Save all attachments from a sender"""

# Get all messages from the inbox
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # 6 is the inbox folder
messages = inbox.Items
message = messages.GetFirst()

# Get all files from the path
files_list = os.listdir(path)

message_name_list =
message_counter = 0

while message:

print(message)

# Check if the message is from the sender
if message.SenderEmailAddress == sender:

# Check if the message name have been already used
if message not in message_name_list:

# Add message name to the list
message_name_list.append(message)

# Add one to msg counter
message_counter += 1

# Get the message date
mail_date = message.SentOn.date()

# Get all attachments from the message and get a count
attachments = message.Attachments
att_count = attachments.Count

# Check if the message have attachments
if att_count >= 1:

# Check if there is more than one attachments
if att_count > 1:

for att in range(att_count):

# Get attachments one by one
nb_att = att + 1
attachment = attachments.Item(nb_att)

# Set the filename for the attachment
filename = "img_" + str(mail_date) + "_" + str(message_counter) + "_" + str(nb_att) + ".jpg"

#check if file is already saved and save if not already saved
if filename not in files_list:
print (filename)
attachment.SaveAsFile(path + "\" + filename)

# Go to a next message
message = messages.GetNext()

else:
# Get the attachment
attachment = attachments.Item(1)

# Set the filename for the attachment
filename = 'img_' + str(mail_date) + "_" + str(message_counter) + '.jpg'

#check if file is already saved and save if not already saved
if filename not in files_list:
print (filename)
attachment.SaveAsFile(path + "\" + filename)

#Go to a next message
message = messages.GetNext()

if __name__ == "__main__":
main()


Normally in the terminal I should see the name of the mail and every saved attachments (called filename in my script). But actually I can only see that in the terminal:



script



script



script



script



And more others "script"



Someone know why no message are print and why "script" is print?
and how to fix that?










share|improve this question
















I'm writing a script for getting every image attachment from a sender in python 3.7 using pypiwin32.



import win32com.client
import click
import os
import logging

@click.command()
@click.option('-s', '--sender', 'sender', help="Sender's mail")
@click.option('-p', '--path', 'path', help="Save path")
def main(sender: str, path: str) -> None:

"""Save all attachments from a sender"""

# Get all messages from the inbox
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
inbox = outlook.GetDefaultFolder(6) # 6 is the inbox folder
messages = inbox.Items
message = messages.GetFirst()

# Get all files from the path
files_list = os.listdir(path)

message_name_list =
message_counter = 0

while message:

print(message)

# Check if the message is from the sender
if message.SenderEmailAddress == sender:

# Check if the message name have been already used
if message not in message_name_list:

# Add message name to the list
message_name_list.append(message)

# Add one to msg counter
message_counter += 1

# Get the message date
mail_date = message.SentOn.date()

# Get all attachments from the message and get a count
attachments = message.Attachments
att_count = attachments.Count

# Check if the message have attachments
if att_count >= 1:

# Check if there is more than one attachments
if att_count > 1:

for att in range(att_count):

# Get attachments one by one
nb_att = att + 1
attachment = attachments.Item(nb_att)

# Set the filename for the attachment
filename = "img_" + str(mail_date) + "_" + str(message_counter) + "_" + str(nb_att) + ".jpg"

#check if file is already saved and save if not already saved
if filename not in files_list:
print (filename)
attachment.SaveAsFile(path + "\" + filename)

# Go to a next message
message = messages.GetNext()

else:
# Get the attachment
attachment = attachments.Item(1)

# Set the filename for the attachment
filename = 'img_' + str(mail_date) + "_" + str(message_counter) + '.jpg'

#check if file is already saved and save if not already saved
if filename not in files_list:
print (filename)
attachment.SaveAsFile(path + "\" + filename)

#Go to a next message
message = messages.GetNext()

if __name__ == "__main__":
main()


Normally in the terminal I should see the name of the mail and every saved attachments (called filename in my script). But actually I can only see that in the terminal:



script



script



script



script



And more others "script"



Someone know why no message are print and why "script" is print?
and how to fix that?







python python-3.x outlook pywin32 win32com






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 15:55







Dimitri Colier

















asked Nov 22 '18 at 15:35









Dimitri ColierDimitri Colier

111




111













  • Maybe this link will help for you: stackoverflow.com/questions/45425251/…

    – Alina Li
    Nov 23 '18 at 8:20



















  • Maybe this link will help for you: stackoverflow.com/questions/45425251/…

    – Alina Li
    Nov 23 '18 at 8:20

















Maybe this link will help for you: stackoverflow.com/questions/45425251/…

– Alina Li
Nov 23 '18 at 8:20





Maybe this link will help for you: stackoverflow.com/questions/45425251/…

– Alina Li
Nov 23 '18 at 8:20












0






active

oldest

votes












Your Answer






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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434231%2fpython-outlook-win32-error-when-getting-every-message-from-outlook-returning%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434231%2fpython-outlook-win32-error-when-getting-every-message-from-outlook-returning%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents