Ejemplo n.º 1
0
def send_mail(subject,
              body_text,
              sendto,
              copyto=None,
              blindcopyto=None,
              attach=None):
    session = DispatchEx('Lotus.NotesSession')
    session.Initialize('your_password')

    server_name = 'your/server'
    db_name = 'your/database.nsf'

    db = session.getDatabase(server_name, db_name)
    if not db.IsOpen:
        try:
            db.Open()
        except pywintypes.com_error:
            print('could not open database: {}'.format(db_name))

    doc = db.CreateDocument()
    doc.ReplaceItemValue("Form", "Memo")
    doc.ReplaceItemValue("Subject", subject)

    # assign random uid because sometimes Lotus Notes tries to reuse the same one
    uid = str(uuid.uuid4().hex)
    doc.ReplaceItemValue('UNIVERSALID', uid)

    # "SendTo" MUST be populated otherwise you get this error:
    # 'No recipient list for Send operation'
    doc.ReplaceItemValue("SendTo", sendto)

    if copyto is not None:
        doc.ReplaceItemValue("CopyTo", copyto)
    if blindcopyto is not None:
        doc.ReplaceItemValue("BlindCopyTo", blindcopyto)

    # body
    body = doc.CreateRichTextItem("Body")
    body.AppendText(body_text)

    # attachment
    if attach is not None:
        attachment = doc.CreateRichTextItem("Attachment")
        for att in attach:
            attachment.EmbedObject(1454, "", att, "Attachment")

    # save in `Sent` view; default is False
    doc.SaveMessageOnSend = True
    doc.Send(False)
Ejemplo n.º 2
0
def send_mail(subject,body_text,sendto,copyto=None,blindcopyto=None,
              attach=None):
    session = DispatchEx('Lotus.NotesSession')
    session.Initialize('your_password')

    server_name = 'your/server'
    db_name = 'your/database.nsf'

    db = session.getDatabase(server_name, db_name)
    if not db.IsOpen:
        try:
            db.Open()
        except pywintypes.com_error:
            print( 'could not open database: {}'.format(db_name) )

    doc = db.CreateDocument()
    doc.ReplaceItemValue("Form","Memo")
    doc.ReplaceItemValue("Subject",subject)

    # assign random uid because sometimes Lotus Notes tries to reuse the same one
    uid = str(uuid.uuid4().hex)
    doc.ReplaceItemValue('UNIVERSALID',uid)

    # "SendTo" MUST be populated otherwise you get this error: 
    # 'No recipient list for Send operation'
    doc.ReplaceItemValue("SendTo", sendto)

    if copyto is not None:
        doc.ReplaceItemValue("CopyTo", copyto)
    if blindcopyto is not None:
        doc.ReplaceItemValue("BlindCopyTo", blindcopyto)

    # body
    body = doc.CreateRichTextItem("Body")
    body.AppendText(body_text)

    # attachment 
    if attach is not None:
        attachment = doc.CreateRichTextItem("Attachment")
        for att in attach:
            attachment.EmbedObject(1454, "", att, "Attachment")

    # save in `Sent` view; default is False
    doc.SaveMessageOnSend = True
    doc.Send(False)
Ejemplo n.º 3
0
def send_mail(subject,
              body_text,
              send_to,
              copyto=None,
              blindcopyto=None,
              attachments=None):

    # connect to Notes COM
    session = DispatchEx('Lotus.NotesSession')
    while True:
        try:
            session.Initialize(input("Notes Password: "******"""
    for server_name and db_name from Notes:
        File > Preferences > Locations > Online > Edit
            server_name = Servers > Home/mail server
            db_name = Mail > Mail file
    """
    db = session.getDatabase(server_name, db_name)
    if not db.IsOpen:
        try:
            db.Open()
        except pywintypes.com_error:
            print(f"could not open database: {db_name}")

    # build document
    doc = db.CreateDocument()
    doc.ReplaceItemValue("Form", "Memo")
    doc.ReplaceItemValue("Subject", subject)

    # assign random uid because sometimes Lotus Notes tries to reuse the same one
    uid = str(uuid.uuid4().hex)
    doc.ReplaceItemValue('UNIVERSALID', uid)

    # "SendTo" MUST be populated otherwise you get this error:
    # 'No recipient list for Send operation'
    doc.ReplaceItemValue("SendTo", send_to)

    if copyto:
        doc.ReplaceItemValue("CopyTo", copyto)
    if blindcopyto:
        doc.ReplaceItemValue("BlindCopyTo", blindcopyto)

    # body
    body = doc.CreateRichTextItem("Body")
    body.AppendText(body_text)

    # attachments
    if attachments:
        email_att_field = doc.CreateRichTextItem("Attachment")
        for attachment in attachments:
            email_att_field.EmbedObject(1454, "", attachment, "Attachment")

    doc.SaveMessageOnSend = True  # show sent email in Notes "Sent" view
    doc.Send(
        False
    )  # not really sure what the arg is for, but makes file sizes massive if True