Archived Forum Post

Index of archived forum posts

Question:

Outlook MAPI Result to EML (Python)

Mar 19 '14 at 11:43

Hi, i´m trying to create an EML-File using chilkat.CkMail(). The results of the Outlook MAPI are Unicode, and the CkMail() Functions do not accept Unicode. So i have to encode the Outlook Results. But if i encode to "utf-8" all umlaute (ü,ä,ö) are replaced by strange signs in the resulting EML-File. I tried using "latin-1" but then i can´t encode Strings that contain Euro-Signs. Do you have any solution to bring unicode-strings in the EML-File?

my code atm:

def DecodeUnicode(pUnicodeString):
    for TryThis in ['latin_1', 'utf8']:
       try:
          Result = pUnicodeString.encode(TryThis)
          return Result
       except:
          pass
    return pUnicodeString

def CreateEMLFile(pItem)
    with tempfile.NamedTemporaryFile(suffix=".eml",prefix="TBTEMP_", delete=False) as nf:
       nf.close()
    newEmail = chilkat.CkEmail()
    newEmail.put_Subject(                   DecodeUnicode(pItem.Subject))
    newEmail.put_FromAddress(               DecodeUnicode(pItem.SenderEmailAddress))
    newEmail.put_FromName(                  DecodeUnicode(pItem.SenderName))
    newEmail.AddTo(                         DecodeUnicode(pItem.ReceivedByName),
                                            "test@test.de")                
    newEmail.AddPlainTextAlternativeBody(   DecodeUnicode(pItem.Body))
    newEmail.AddHtmlAlternativeBody(        DecodeUnicode(pItem.HTMLBody))
    newEmail.SaveEml(nf.name)
    return nf.name