Выполнить Javascript письма, отправленного с помощью python smtplib - PullRequest
0 голосов
/ 09 июня 2018

Я занимаюсь электронной почтой и хотел узнать, возможно ли выполнить код Javascript при отправке и отправке электронной почты с использованием smtplib и почтовых библиотек, а также когда ваше сообщение содержит HTML-код?

Кажется, что ничего не добавляется.

HTML-файл:

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
</div>
   <p class='Test'>This is my first sentence</p>

   <script type="text/javascript">
       var list = document.querySelector('p.Test');
       list.innerHTML = "I want to change it";
   </script>
</body>
</html>

Код Python:

import smtplib
from email.message import EmailMessage


def ConnectServer(User, Pass, Host):
    SMTPServer = smtplib.SMTP_SSL(Host)
    SMTPServer.ehlo()
    SMTPServer.login(User, Pass)
    return SMTPServer

def SendMail(Server, src, dst, data):
    msg = EmailMessage()
    msg['From'] = src
    msg['To'] = dst
    msg['Subject'] = 'Test envoi python'
    msg.add_alternative(data, 'html')
    Server.send_message(msg, src, dst)


def main():
    #Define email adresses
    me = 'AN_EMAIL@MAIL.com'
    me2 = 'AN_OTHER_EMAIL@mail.com'
    Server = ConnectServer(me, 'PASS', 'smtp.gmail.com')


    with open('HTML PATH HERE', 'r', encoding='utf8') as File:
        data = File.read()
        SendMail(Server, me, me2, data)
    pass

if __name__ == '__main__':
    main()

Надеюсь, все понятно.

1 Ответ

0 голосов
/ 22 сентября 2018

Насколько я знаю, мы не можем, я тоже пытался это сделать, я хотел включить строку поиска для содержимого таблицы в почте.

"No. JavaScript won't work in mails. A cool way to implement this feature 
 would be to include an image that points to your server, where you generate 
 the weather report server side and render it as an image, and return it to 
 the client.

 Note though that Gmail caches images and depending on when he does it that 
 might not be refreshed."

Источник: https://www.quora.com/

...