def enviarCorreo(correoEntry):
    try:
        correo = correoEntry.get()
        mailman = chilkat.CkMailMan()

        success = mailman.UnlockComponent("30-day trial")
        if (success != True):
            return messagebox.showinfo("Atención!",
                                       "El correo ingresado no es válido")
            sys.exit()

        mailman.put_SmtpHost("smtp.gmail.com")
        mailman.put_SmtpUsername("*****@*****.**")
        mailman.put_SmtpPassword("basepelis123")

        email = chilkat.CkEmail()

        fileOnDisk = "images/" + clasePelicula.getNombre() + ".jpg"
        filePathInHtml = clasePelicula.getNombre() + ".jpg"

        success = email.AddRelatedFile2(fileOnDisk, filePathInHtml)
        if (success != True):
            return messagebox.showinfo("Atención!",
                                       "El correo ingresado no es válido")
            sys.exit()

        htmlBody = "<html><body> Información de la película " + clasePelicula.getNombre(
        ) + "<br> Tipo: " + clasePelicula.getTipo(
        ) + "<br> Duración: " + clasePelicula.getDuracion(
        ) + "<br> Género: " + clasePelicula.getGenero(
        ) + "<br> Directores: " + clasePelicula.getDirectores(
        ) + "<br> Escritores: " + clasePelicula.getEscritores(
        ) + "<br> Actores: " + clasePelicula.getActores(
        ) + "<br> Premios: " + clasePelicula.getPremios(
        ) + "<br> Fecha de Lanzamient: " + clasePelicula.getFechaLanzamiento(
        ) + "<br> Año: " + clasePelicula.getAnno(
        ) + "<br> Idiomas: " + clasePelicula.getIdiomas(
        ) + "<br> Sinopsis: " + clasePelicula.getSinopsis(
        ) + "<br> Metascore: " + clasePelicula.getMetascore(
        ) + "<br>  ImDBRate: " + clasePelicula.getImDBRate(
        ) + "<br> Poster <br><img src=\"" + clasePelicula.getNombre(
        ) + ".jpg\"" "> </body></html>"

        email.SetHtmlBody(htmlBody)
        email.put_Subject("Recomendación de película.")
        success = email.AddTo("Admin", str(correo))
        email.put_From("<*****@*****.**>")

        success = mailman.SendEmail(email)
        if (success != True):
            return messagebox.showinfo("Atención!",
                                       "El correo ingresado no es válido")

        else:
            return messagebox.showinfo(
                "Atención!", "El correo se ha enviado satisfactoriamente!.")
    except:
        return messagebox.showinfo("Atención!",
                                   "El correo ingresado no es válido")
import sys
import chilkat

email = chilkat.CkEmail()

#  Add a PFX (or .p12) to be used for decryption
success = email.AddPfxSourceFile("myCert.p12", "passwordForP12")
if (success != True):
    print(email.lastErrorText())
    sys.exit()

#  Loading the .eml automatically decrypts.
success = email.LoadEml("encrypted.eml")
if (success != True):
    print(email.lastErrorText())
    sys.exit()

#  The email now exists as it was prior to encryption.
#  Your app may access the email's subject, body, attachments,
#  etc. using the Chilkat Email API...

#  Save the decrypted email:
success = email.SaveEml("decrypted.eml")
if (success != True):
    print(email.lastErrorText())
    sys.exit()

print("Success.")
Example #3
0
def generateEML(mail):
    sub = (mail.Subject).replace(' ', '')
    body = mail.Body.encode("utf-8")
    recipients = mail.Recipients
    sender_email = mail.SenderEmailAddress
    sender_name = mail.SenderName
    attachments = mail.Attachments
    #    to = mail.To
    #    cc = mail.CC
    #    rec_date = mail.ReceivedTime

    email = chilkat.CkEmail()
    email.put_Subject(ustr(sub).encode('iso-8859-1'))
    email.put_Body(ustr(body).encode('utf-8'))
    email.put_FromAddress(ustr(sender_email).encode('iso-8859-1'))
    email.put_From(ustr(sender_name).encode('iso-8859-1'))

    for i in xrange(1, recipients.Count + 1):
        name = ustr(recipients.Item(i).Name).encode('iso-8859-1')
        address = ustr(recipients.Item(i).Address).encode('iso-8859-1')
        email.AddTo(name, address)

#    email.AddMultipleTo(to)
#    email.AddMultipleCC(cc)
#    win32ui.MessageBox("cccc---"+str(dir(cc)),'')
#    for i in xrange(1, cc.Count+1):
#        name = ustr(recipients.Item(i).Name).encode('iso-8859-1')
#        address = ustr(recipients.Item(i).Address).encode('iso-8859-1')
#        email.AddCC(name,address)

    eml_name = ustr(sub).encode('iso-8859-1') + '-' + str(mail.EntryID)[-9:]
    ls = ['*', '/', '\\', '<', '>', ':', '?', '"', '|', '\t', '\n']
    attachments_folder_path = os.path.abspath(
        os.path.dirname(__file__) + "\\dialogs\\resources\\attachments\\")
    if not os.path.exists(attachments_folder_path):
        os.makedirs(attachments_folder_path)
    for i in xrange(1, attachments.Count + 1):
        fn = eml_name + '-' + ustr(
            attachments[i].FileName).encode('iso-8859-1')
        for c in ls:
            fn = fn.replace(c, '')
        if len(fn) > 64:
            l = 64 - len(fn)
            f = fn.split('-')
            fn = '-'.join(f[1:])
            if len(fn) > 64:
                l = 64 - len(fn)
                f = fn.split('.')
                fn = f[0][0:l] + '.' + f[-1]
        att_file = os.path.join(attachments_folder_path, fn)
        if os.path.exists(att_file):
            os.remove(att_file)
        f1 = att_file
        attachments[i].SaveAsFile(att_file)
        contentType = email.addFileAttachment(att_file)
        if (contentType == None):
            print mail.lastErrorText()
            sys.exit()

    mails_folder_path = os.path.abspath(
        os.path.dirname(__file__) + "\\dialogs\\resources\\mails\\")
    if not os.path.exists(mails_folder_path):
        os.makedirs(mails_folder_path)
    for c in ls:
        eml_name = eml_name.replace(c, '')
    if len(eml_name) > 64:
        l = 64 - len(eml_name)
        f = eml_name.split('-')
        eml_name = f[0][0:l] + '.' + f[-1]
    eml_path = ustr(os.path.join(mails_folder_path,
                                 eml_name + ".eml")).encode('iso-8859-1')
    success = email.SaveEml(eml_path)
    if (success == False):
        print email.lastErrorText()
        sys.exit()

    print "Saved EML!", eml_path
    return eml_path
Example #4
0
def generateEML(mail):
    sub = (mail.Subject).replace(' ','')
    body = mail.Body.encode("utf-8")
    recipients = mail.Recipients
    sender_email = mail.SenderEmailAddress
    attachments=mail.Attachments

    cemail = chilkat.CkEmail()
    cemail.put_Subject (ustr(sub).encode('iso-8859-1'))
    cemail.put_Body (ustr(body).encode('utf-8'))
    cemail.put_FromAddress (ustr(sender_email).encode('iso-8859-1'))
    cemail.put_From (ustr(sender_email).encode('iso-8859-1'))

    for i in xrange(1, recipients.Count+1):
        name = ustr(recipients.Item(i).Name).encode('iso-8859-1')
        address = ustr(recipients.Item(i).Address).encode('iso-8859-1')
        cemail.AddTo(name,address)

    eml_name= ustr(sub).encode('iso-8859-1')+'-'+str(mail.EntryID)[-9:]
    ls = ['*', '/', '\\', '<', '>', ':', '?', '"', '|', '\t', '\n']
    mails_folder_path = os.path.abspath("%temp%\\dialogs\\resources\\mails\\")
    attachments_folder_path = mails_folder_path + "\\attachments\\"
    if not os.path.exists(attachments_folder_path):
        os.makedirs(attachments_folder_path)
    for i in xrange(1, attachments.Count+1):
        fn = eml_name + '-' + ustr(attachments[i].FileName).encode('iso-8859-1')
        for c in ls:
            fn = fn.replace(c,'')
        if len(fn) > 64:
            l = 64 - len(fn)
            f = fn.split('-')
            fn = '-'.join(f[1:])
            if len(fn) > 64:
                l = 64 - len(fn)
                f = fn.split('.')
                fn = f[0][0:l] + '.' + f[-1]
        att_file = os.path.join(attachments_folder_path, fn)
        if os.path.exists(att_file):
            os.remove(att_file)
        attachments[i].SaveAsFile(att_file)
        contentType = cemail.addFileAttachment(att_file)
        if (contentType == None ):
            print mail.lastErrorText()
            sys.exit()


    if not os.path.exists(mails_folder_path):
        os.makedirs(mails_folder_path)
    for c in ls:
        eml_name = eml_name.replace(c,'')
    if len(eml_name) > 64:
       l = 64 - len(eml_name)
       f = eml_name.split('-')
       eml_name = f[0][0:l] + '.' + f[-1]
    eml_path = ustr(os.path.join(mails_folder_path,eml_name+".eml")).encode('iso-8859-1')
    success = cemail.SaveEml(eml_path)
    fp = open(eml_path, 'rb')
    new_mail = email.message_from_file(fp)
    fp.close()
    if (success == False):
        print cemail.lastErrorText()
        sys.exit()
    return new_mail, eml_path