#StackBounty: #python #python-3.x #email #mime-types #mime What should be the content type to set for a multipart email after parsing a…

Bounty: 100

I have a multipart email with all types of attachments ie. multiple email, plain text, pdf attachments, inline images and html too. After walking through the different parts of the multipart body and adding some text to the body of the main email, I wish to regenerate the whole email as an original. What should be the correct method to do that. Using python 3.6. Code snippet what I have tried is as follows:

mail_attached_bool = False
new_message1 = email.message.EmailMessage()
attached_bool = False

mhtml = 'Modified html variable'
mbody = 'Modified text variable'

# while parsing the multipart of the raw message: msg
if msg.is_multipart():
    for part in msg.walk():
        if part.get_content_type() == 'multipart/report':
            new_message.attach(mbody)
            if mhtml:            
                new_message.attach(mhtml)

            for rel1 in part.walk():
                if rel1.get_content_type() == 'message/delivery-status':
                    new_message.attach(rel1)
                if rel1.get_content_type() == 'text/rfc822-headers':
                    new_message.attach(rel1)

        if part.get_content_type() in ["multipart/related",
                                       "multipart/mixed"]:
            new_message1.set_type("multipart/related")
            if mhtml:
                new_message1.attach(mhtml)
                print(999999)
            elif mbody:
                if mbody == '':
                    mbody = MIMEText(warning_txt,'plain')
                new_message1.attach(mbody)

        for rel in part.walk():
            mail_attached_bool = False
            attached_bool = False
            print(rel.get_content_type(), '------------cccccccc')
            # other kinds of attachments
            cdispo = str(rel.get('Content-Disposition'))
            attach = re.compile('application/*')
            attachment = attach.search(rel.get_content_type())

            if rel.get_content_type() in ['message/rfc822',]:
                new_message1.set_type('multipart/related')
                print(rel.get_content_type(), '----------content type')
                mail_attached_bool = True
                attached_bool = True
                x += 1
            
            if rel.is_multipart() and rel.get_content_type() 
               not in 
               ["multipart/alternative",
                "message/rfc822"
               ]:
                new_message1.set_type(rel.get_content_type())

            # ignore the first html as its the mail body
            if rel.get_content_type() == "text/html" and cdispo=='None':
                i += 1
                if i == 1 and html_body:
                    continue
                print('i: ',i)
            # ignore the first plain text as its the mail body
            if rel.get_content_type() == "text/plain" and cdispo=='None':
                j += 1
                if j == 1 and text_body:
                    continue
                print('j: ',j)

            #--------------#                    
            if 1:#rel.get_content_type() != 'message/rfc822':#mail_attached_bool is False:
                # has mail content apart from body (ios)
                if rel.get_content_type() == "text/html":
                    new_message1.attach(rel)
                    print(rel.get_filename(),'-----   html  attached')

                if rel.get_content_type() == "text/plain" and 
                   rel.get('Content-Disposition') in [None, "inline"]:
                    new_message1.attach(rel)
                    print('---------------text attachment', 666666)

                if rel.get_content_type() in ['image/png',
                                              'image/jpeg',
                                              'image/jpg'] 
                                              or ('attachment' in cdispo) 
                                    or ('inline' in cdispo) or (attachment):

                    # inline images and text
                    if "inline" in cdispo and 
                       not rel.get_content_type() in [
                           "text/plain",
                       ] 
                           and not attached_bool:
                        attached_bool = True
                        new_message1.attach(rel)
                        
                    if attachment or "attachment" in cdispo and 
                       (not attached_bool) or cdispo == 'None':
                        new_message1.attach(rel)
                        attached_bool = True

                    elif cdispo == 'None' and (not attached_bool):
                        new_message1.attach(rel)
                        print('attaching here')

                if rel.get_content_type() in ['text/calendar']:
                    new_message1.attach(rel)

            if mail_attached_bool:
                new_message1.attach(rel)

        new_message.set_type('multipart/alternative')
        new_message.attach(new_message1)
        if new_message1:
            print('new_message1 exists')
            break

Then send the mail.
When the mail is sent it is attaching the main mail body and its attachment 2 times in the new message object. Why does this happen? What is the correct content type to set for the new mail?


Get this bounty!!!

#StackBounty: #email #imap #microsoft-outlook-2016 #yahoo-messenger Exporting Yahoo emails to Outlook 2016 won't copy folders, even…

Bounty: 50

UPDATE: I’d still like to do this, but with Outlook 2016.

I am trying to copy my Yahoo emails into Outlook 2010. However, when I select to send/receive all folders, only the Inbox will copy to Outlook. All of my other personal folders do not copy. Of course this didn’t work using POP3, but I even tried using IMAP and it still won’t copy my named folders from Yahoo to Outlook.

I used the following steps from Yahoo:

IMAP server settings for Yahoo Mail

IMAP is the best way to connect your Yahoo Mail account to a desktop mail client or mobile
app. It allows 2-way syncing, which means everything you do remotely
is reflected in your Yahoo Mail account no matter where or how you
access it. Here are the settings you’ll need to configure your mail
client or app.

Incoming Mail (IMAP) Server

  • Server – imap.mail.yahoo.com
  • Port – 993
  • Requires SSL – Yes

Outgoing Mail (SMTP) Server

  • Server – smtp.mail.yahoo.com
  • Port – 465 or 587
  • Requires SSL – Yes
    Requires authentication – Yes

Your login info

  • Email address – Your full email address (name@domain.com)
  • Password – Your account’s password
  • Requires authentication – Yes

If you need specific instructions for your mail client or app, reach out to its manufacturer.

Any idea how to rectify this problem??


Get this bounty!!!

#StackBounty: #email #imap #microsoft-outlook-2016 #yahoo-messenger Exporting Yahoo emails to Outlook 2016 won't copy folders, even…

Bounty: 50

UPDATE: I’d still like to do this, but with Outlook 2016.

I am trying to copy my Yahoo emails into Outlook 2010. However, when I select to send/receive all folders, only the Inbox will copy to Outlook. All of my other personal folders do not copy. Of course this didn’t work using POP3, but I even tried using IMAP and it still won’t copy my named folders from Yahoo to Outlook.

I used the following steps from Yahoo:

IMAP server settings for Yahoo Mail

IMAP is the best way to connect your Yahoo Mail account to a desktop mail client or mobile
app. It allows 2-way syncing, which means everything you do remotely
is reflected in your Yahoo Mail account no matter where or how you
access it. Here are the settings you’ll need to configure your mail
client or app.

Incoming Mail (IMAP) Server

  • Server – imap.mail.yahoo.com
  • Port – 993
  • Requires SSL – Yes

Outgoing Mail (SMTP) Server

  • Server – smtp.mail.yahoo.com
  • Port – 465 or 587
  • Requires SSL – Yes
    Requires authentication – Yes

Your login info

  • Email address – Your full email address (name@domain.com)
  • Password – Your account’s password
  • Requires authentication – Yes

If you need specific instructions for your mail client or app, reach out to its manufacturer.

Any idea how to rectify this problem??


Get this bounty!!!

#StackBounty: #email #imap #microsoft-outlook-2016 #yahoo-messenger Exporting Yahoo emails to Outlook 2016 won't copy folders, even…

Bounty: 50

UPDATE: I’d still like to do this, but with Outlook 2016.

I am trying to copy my Yahoo emails into Outlook 2010. However, when I select to send/receive all folders, only the Inbox will copy to Outlook. All of my other personal folders do not copy. Of course this didn’t work using POP3, but I even tried using IMAP and it still won’t copy my named folders from Yahoo to Outlook.

I used the following steps from Yahoo:

IMAP server settings for Yahoo Mail

IMAP is the best way to connect your Yahoo Mail account to a desktop mail client or mobile
app. It allows 2-way syncing, which means everything you do remotely
is reflected in your Yahoo Mail account no matter where or how you
access it. Here are the settings you’ll need to configure your mail
client or app.

Incoming Mail (IMAP) Server

  • Server – imap.mail.yahoo.com
  • Port – 993
  • Requires SSL – Yes

Outgoing Mail (SMTP) Server

  • Server – smtp.mail.yahoo.com
  • Port – 465 or 587
  • Requires SSL – Yes
    Requires authentication – Yes

Your login info

  • Email address – Your full email address (name@domain.com)
  • Password – Your account’s password
  • Requires authentication – Yes

If you need specific instructions for your mail client or app, reach out to its manufacturer.

Any idea how to rectify this problem??


Get this bounty!!!

#StackBounty: #email #imap #microsoft-outlook-2016 #yahoo-messenger Exporting Yahoo emails to Outlook 2016 won't copy folders, even…

Bounty: 50

UPDATE: I’d still like to do this, but with Outlook 2016.

I am trying to copy my Yahoo emails into Outlook 2010. However, when I select to send/receive all folders, only the Inbox will copy to Outlook. All of my other personal folders do not copy. Of course this didn’t work using POP3, but I even tried using IMAP and it still won’t copy my named folders from Yahoo to Outlook.

I used the following steps from Yahoo:

IMAP server settings for Yahoo Mail

IMAP is the best way to connect your Yahoo Mail account to a desktop mail client or mobile
app. It allows 2-way syncing, which means everything you do remotely
is reflected in your Yahoo Mail account no matter where or how you
access it. Here are the settings you’ll need to configure your mail
client or app.

Incoming Mail (IMAP) Server

  • Server – imap.mail.yahoo.com
  • Port – 993
  • Requires SSL – Yes

Outgoing Mail (SMTP) Server

  • Server – smtp.mail.yahoo.com
  • Port – 465 or 587
  • Requires SSL – Yes
    Requires authentication – Yes

Your login info

  • Email address – Your full email address (name@domain.com)
  • Password – Your account’s password
  • Requires authentication – Yes

If you need specific instructions for your mail client or app, reach out to its manufacturer.

Any idea how to rectify this problem??


Get this bounty!!!

#StackBounty: #email #imap #microsoft-outlook-2016 #yahoo-messenger Exporting Yahoo emails to Outlook 2016 won't copy folders, even…

Bounty: 50

UPDATE: I’d still like to do this, but with Outlook 2016.

I am trying to copy my Yahoo emails into Outlook 2010. However, when I select to send/receive all folders, only the Inbox will copy to Outlook. All of my other personal folders do not copy. Of course this didn’t work using POP3, but I even tried using IMAP and it still won’t copy my named folders from Yahoo to Outlook.

I used the following steps from Yahoo:

IMAP server settings for Yahoo Mail

IMAP is the best way to connect your Yahoo Mail account to a desktop mail client or mobile
app. It allows 2-way syncing, which means everything you do remotely
is reflected in your Yahoo Mail account no matter where or how you
access it. Here are the settings you’ll need to configure your mail
client or app.

Incoming Mail (IMAP) Server

  • Server – imap.mail.yahoo.com
  • Port – 993
  • Requires SSL – Yes

Outgoing Mail (SMTP) Server

  • Server – smtp.mail.yahoo.com
  • Port – 465 or 587
  • Requires SSL – Yes
    Requires authentication – Yes

Your login info

  • Email address – Your full email address (name@domain.com)
  • Password – Your account’s password
  • Requires authentication – Yes

If you need specific instructions for your mail client or app, reach out to its manufacturer.

Any idea how to rectify this problem??


Get this bounty!!!

#StackBounty: #email #imap #microsoft-outlook-2016 #yahoo-messenger Exporting Yahoo emails to Outlook 2016 won't copy folders, even…

Bounty: 50

UPDATE: I’d still like to do this, but with Outlook 2016.

I am trying to copy my Yahoo emails into Outlook 2010. However, when I select to send/receive all folders, only the Inbox will copy to Outlook. All of my other personal folders do not copy. Of course this didn’t work using POP3, but I even tried using IMAP and it still won’t copy my named folders from Yahoo to Outlook.

I used the following steps from Yahoo:

IMAP server settings for Yahoo Mail

IMAP is the best way to connect your Yahoo Mail account to a desktop mail client or mobile
app. It allows 2-way syncing, which means everything you do remotely
is reflected in your Yahoo Mail account no matter where or how you
access it. Here are the settings you’ll need to configure your mail
client or app.

Incoming Mail (IMAP) Server

  • Server – imap.mail.yahoo.com
  • Port – 993
  • Requires SSL – Yes

Outgoing Mail (SMTP) Server

  • Server – smtp.mail.yahoo.com
  • Port – 465 or 587
  • Requires SSL – Yes
    Requires authentication – Yes

Your login info

  • Email address – Your full email address (name@domain.com)
  • Password – Your account’s password
  • Requires authentication – Yes

If you need specific instructions for your mail client or app, reach out to its manufacturer.

Any idea how to rectify this problem??


Get this bounty!!!

#StackBounty: #email #imap #microsoft-outlook-2016 #yahoo-messenger Exporting Yahoo emails to Outlook 2016 won't copy folders, even…

Bounty: 50

UPDATE: I’d still like to do this, but with Outlook 2016.

I am trying to copy my Yahoo emails into Outlook 2010. However, when I select to send/receive all folders, only the Inbox will copy to Outlook. All of my other personal folders do not copy. Of course this didn’t work using POP3, but I even tried using IMAP and it still won’t copy my named folders from Yahoo to Outlook.

I used the following steps from Yahoo:

IMAP server settings for Yahoo Mail

IMAP is the best way to connect your Yahoo Mail account to a desktop mail client or mobile
app. It allows 2-way syncing, which means everything you do remotely
is reflected in your Yahoo Mail account no matter where or how you
access it. Here are the settings you’ll need to configure your mail
client or app.

Incoming Mail (IMAP) Server

  • Server – imap.mail.yahoo.com
  • Port – 993
  • Requires SSL – Yes

Outgoing Mail (SMTP) Server

  • Server – smtp.mail.yahoo.com
  • Port – 465 or 587
  • Requires SSL – Yes
    Requires authentication – Yes

Your login info

  • Email address – Your full email address (name@domain.com)
  • Password – Your account’s password
  • Requires authentication – Yes

If you need specific instructions for your mail client or app, reach out to its manufacturer.

Any idea how to rectify this problem??


Get this bounty!!!

#StackBounty: #email #imap #microsoft-outlook-2016 #yahoo-messenger Exporting Yahoo emails to Outlook 2016 won't copy folders, even…

Bounty: 50

UPDATE: I’d still like to do this, but with Outlook 2016.

I am trying to copy my Yahoo emails into Outlook 2010. However, when I select to send/receive all folders, only the Inbox will copy to Outlook. All of my other personal folders do not copy. Of course this didn’t work using POP3, but I even tried using IMAP and it still won’t copy my named folders from Yahoo to Outlook.

I used the following steps from Yahoo:

IMAP server settings for Yahoo Mail

IMAP is the best way to connect your Yahoo Mail account to a desktop mail client or mobile
app. It allows 2-way syncing, which means everything you do remotely
is reflected in your Yahoo Mail account no matter where or how you
access it. Here are the settings you’ll need to configure your mail
client or app.

Incoming Mail (IMAP) Server

  • Server – imap.mail.yahoo.com
  • Port – 993
  • Requires SSL – Yes

Outgoing Mail (SMTP) Server

  • Server – smtp.mail.yahoo.com
  • Port – 465 or 587
  • Requires SSL – Yes
    Requires authentication – Yes

Your login info

  • Email address – Your full email address (name@domain.com)
  • Password – Your account’s password
  • Requires authentication – Yes

If you need specific instructions for your mail client or app, reach out to its manufacturer.

Any idea how to rectify this problem??


Get this bounty!!!

#StackBounty: #email #imap #microsoft-outlook-2016 #yahoo-messenger Exporting Yahoo emails to Outlook 2016 won't copy folders, even…

Bounty: 50

UPDATE: I’d still like to do this, but with Outlook 2016.

I am trying to copy my Yahoo emails into Outlook 2010. However, when I select to send/receive all folders, only the Inbox will copy to Outlook. All of my other personal folders do not copy. Of course this didn’t work using POP3, but I even tried using IMAP and it still won’t copy my named folders from Yahoo to Outlook.

I used the following steps from Yahoo:

IMAP server settings for Yahoo Mail

IMAP is the best way to connect your Yahoo Mail account to a desktop mail client or mobile
app. It allows 2-way syncing, which means everything you do remotely
is reflected in your Yahoo Mail account no matter where or how you
access it. Here are the settings you’ll need to configure your mail
client or app.

Incoming Mail (IMAP) Server

  • Server – imap.mail.yahoo.com
  • Port – 993
  • Requires SSL – Yes

Outgoing Mail (SMTP) Server

  • Server – smtp.mail.yahoo.com
  • Port – 465 or 587
  • Requires SSL – Yes
    Requires authentication – Yes

Your login info

  • Email address – Your full email address (name@domain.com)
  • Password – Your account’s password
  • Requires authentication – Yes

If you need specific instructions for your mail client or app, reach out to its manufacturer.

Any idea how to rectify this problem??


Get this bounty!!!