Exemplo n.º 1
0
def send_email_main(address,title,cmd,mailtype,intromessage,bodytextlist=[]):
	
	# mailtype option
	# "report"
	# "alert"
	if mailtype=="report":
		starttitle="Report:"
		showtable=True
		showpicture=True
		showlink=True

			
	elif mailtype=="alert":
		starttitle="Alert:"
		showtable=False
		showpicture=False
		showlink=True

	
	
	currentdate=datetime.datetime.now().strftime("%y-%m-%d,%H:%M")
	# got credentials here !
	user=emaildbmod.getaddress()
	pwd=emaildbmod.getpassword()
	recipient=address

	# check IP address
	iplocal=networkmod.get_local_ip()	
	ipext=networkmod.EXTERNALIPADDR
	if ipext=="":
		logger.info('Stored external IP address is empty, try to get it from network')
		ipext=networkmod.get_external_ip()
		
	print "Try to send mail"	
	# subject of the mail
	subject=starttitle +" " + title + "  " + currentdate
	htmlbody=create_htmlopen()
	htmlbody=htmlbody+create_htmlintro(intromessage)+create_htmlbody(bodytextlist)
	
	if showlink:
		if ipext=="":
			print "No external IP address available"
			logger.error('Unable to get external IP address')		
		else:		
			port=str(networkmod.PUBLICPORT)
			if cmd=="mail+info+link":
				htmlbody=htmlbody+create_htmladdresses(ipext, iplocal, port)
	if showtable:
		# table with information
		matrixinfo=sensordbmod.sensorsysinfomatrix()
		htmlbody=htmlbody+create_htmlmatrix(matrixinfo)
		matrixinfo=actuatordbmod.sensorsysinfomatrix()
		htmlbody=htmlbody+create_htmlmatrix(matrixinfo)
	htmlbody=htmlbody+create_htmlclose()
	issent=send_email_html(user, pwd, recipient, subject, htmlbody, showpicture)
	if (issent) and (showlink) and (ipext!=""):
		global IPEXTERNALSENT
		IPEXTERNALSENT=ipext
	return issent
Exemplo n.º 2
0
def send_email_main(address, title, cmd, mailtype, intromessage):

    # mailtype option
    # "report"
    # "alert"
    if mailtype == "report":
        starttitle = "Report:"
        showtable = True
        showpicture = True
        showlink = True

    elif mailtype == "alert":
        starttitle = "Alert:"
        showtable = False
        showpicture = False
        showlink = True

    currentdate = datetime.datetime.now().strftime("%y-%m-%d,%H:%M")
    # got credentials here !
    user = emaildbmod.getaddress()
    pwd = emaildbmod.getpassword()
    recipient = address

    # check IP address
    iplocal = networkmod.get_local_ip()
    ipext = networkmod.get_external_ip()
    if ipext == "":
        print "No external IP address, mail is not sent"
        logger.error('Unable to get external IP address, mail is not sent')
        return False
    else:
        print "Try to send mail"
        # subject of the mail
        subject = starttitle + " " + title + "  " + currentdate
        htmlbody = create_htmlopen()
        htmlbody = htmlbody + create_htmlintro(intromessage)
        if showlink:
            port = str(networkmod.PUBLICPORT)
            if cmd == "mail+info+link":
                htmlbody = htmlbody + create_htmladdresses(
                    ipext, iplocal, port)
        if showtable:
            # table with information
            matrixinfo = sensordbmod.sensorsysinfomatrix()
            htmlbody = htmlbody + create_htmlmatrix(matrixinfo)
            matrixinfo = actuatordbmod.sensorsysinfomatrix()
            htmlbody = htmlbody + create_htmlmatrix(matrixinfo)
        htmlbody = htmlbody + create_htmlclose()
        issent = send_email_html(user, pwd, recipient, subject, htmlbody,
                                 showpicture)
        if issent:
            global IPEXTERNALSENT
            IPEXTERNALSENT = ipext
    return issent
Exemplo n.º 3
0
def send_email_main(address,
                    title,
                    cmd,
                    mailtype,
                    intromessage,
                    bodytextlist=[]):

    # mailtype option
    # "report"
    # "alert"
    if mailtype == "report":
        starttitle = "Report:"
        showtable = True
        showpicture = True
        showlink = True

    elif mailtype == "alert":
        starttitle = "Alert:"
        showtable = False
        showpicture = False
        showlink = True

    elif mailtype == "info":
        starttitle = "Info:"
        showtable = False
        showpicture = False
        showlink = True

    currentdate = datetime.datetime.now().strftime("%y-%m-%d,%H:%M")
    # got credentials here !
    user = emaildbmod.getaddress()
    pwd = emaildbmod.getpassword()
    recipient = address

    # check IP address
    iplocal = networkmod.get_local_ip()
    ipext = networkmod.EXTERNALIPADDR
    if ipext == "":
        logger.info(
            'Stored external IP address is empty, try to get it from network')
        ipext = networkmod.get_external_ip()

    print("Try to send mail")
    # subject of the mail
    subject = starttitle + " " + title + "  " + currentdate
    htmlbody = create_htmlopen()
    htmlbody = htmlbody + create_htmlintro(intromessage) + create_htmlbody(
        bodytextlist)

    if showlink:
        if ipext == "":
            print("No external IP address available")
            logger.error('Unable to get external IP address')
        else:
            port = str(networkmod.PUBLICPORT)
            if cmd == "mail+info+link":
                addresslist = []
                descriptionlist = []
                addresslist.append(iplocal)
                descriptionlist.append("Link for local Access")
                addresslist.append(ipext)
                descriptionlist.append("Link for Remote Access")
                customURL = networkmod.getCUSTOMURL()
                if not customURL == "":
                    addresslist.append(customURL)
                    descriptionlist.append("your Link")
                print("Mail url list ", addresslist)
                htmlbody = htmlbody + create_htmladdresses(
                    descriptionlist, addresslist, port)

    if showtable:
        # table with information
        matrixinfo = sensordbmod.sensorsysinfomatrix()
        htmlbody = htmlbody + create_htmlmatrix(matrixinfo)
        matrixinfo = actuatordbmod.sensorsysinfomatrix()
        htmlbody = htmlbody + create_htmlmatrix(matrixinfo)
    htmlbody = htmlbody + create_htmlclose()
    issent = send_email_html(user, pwd, recipient, subject, htmlbody,
                             showpicture)
    if (issent) and (showlink) and (ipext != ""):
        global IPEXTERNALSENT
        IPEXTERNALSENT = ipext
    return issent