Hi,

I am using the following code to send mail from a open window in maya application. This gives me following error. I think it says that A2 is not created. What is a possible way to have this code send a mail.


BRgds,

kNish

# Error: name 'A2' is not defined
# Traceback (most recent call last):
# File "<maya console>", line 1, in <module>
# NameError: name 'A2' is not defined #

import maya.cmds as cmds
import smtplib
import os


class pMailmsg:
    "send message modules"
    def __init__(self):
        self.fUser = os.getenv("USERNAME")
        self.tUser = "ppro@eyeqube.com"
        self.conts = ""

    def pSendmsg(self,fromUser,toUser,contents):
        fU = cmds.textField(fromUser, query = True, text = True)
        tU = cmds.textField(toUser, query = True, text = True)
        co = cmds.textField(contents, query = True, text = True)
        cServer = smtplib.SMTP("xxx.xxx.x.x:xx")
        cServer.sendmail = (fU, tU, co)
        cServer.quit()
       
    def pShowWindow(self):
        fromWho = self.fUser
        toWhom = self.tUser
        window = cmds.window(width=150, height = 150)
        form   = cmds.formLayout(numberOfDivisions = 200)
        fromText = cmds.text(label='From : ')
        fromUser = cmds.textField(width = 250)

        toText   = cmds.text(label = 'To : ')
        toUser   = cmds.textField(width = 250)
        subjectText = cmds.text(label = 'Subject : ')
        subject  = cmds.textField(width = 250)
        contentsText = cmds.text(label = 'Contents : ')
        contents = cmds.scrollField(editable = True, wordWrap = True, width = 250, height = 100)
        submit   = cmds.button(label = 'Send Mail', command = ('pSendmsg()'))

        cmds.textField(fromUser, edit = True, text = (fromWho + '@eyeqube.com'), enable = False)
        cmds.textField(toUser, edit = True, text = toWhom, enable = False)
        cmds.textField(subject, edit = True,enable = False)

        cmds.formLayout( form, edit=True, attachForm=[(fromText, 'left', 5), (fromText, 'top', 5), (toText, 'left', 15), (fromUser, 'top', 5), (contents, 'left', 5), (submit, 'left', 165) ],
        attachControl=[(toText, 'top', 15, fromText), (subjectText, 'top', 25, toText), (contentsText, 'top',25,subjectText), (fromUser, 'left', 15, fromText), (toUser, 'top', 15, fromUser), (toUser, 'left', 15, toText), (subject, 'top', 15, toUser), (subject, 'left', 10, subjectText), (contents, 'top', 15, subject), (contents, 'left', 5, contentsText), (submit, 'top', 15, contents)])
        cmds.showWindow( window )
       
       
c = pMailmsg()
c.pShowWindow()

Since there is no A2 in your code; and judging by the content of the error message; I would assume that you have imported the maya.cmds module incorrectly. I would look into the documentation for an example of how to properly use said module.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.