カワセミを2個体確認。
この鳥は?? アオサギの親かな?
STARTTLSを使わない場合
import smtplib, ssl
#送信に利用するメールサーバの設定(プロバイダーのメールアカウント、SMTPサーバー)
username= "aaa@bbb.ccc.ddd"
password= "xxxxx"
mail_server="smtp.eeee.ffff" # SMTP Server
port=465
#偽装送信元
fake_from= "donaldtrump@gmail.com"
fake_name= "Donald Trump"
#メールの宛先
to_email= 'hoge@hoge.hoge'
to_name= 'hoge@hoge.hoge'
subject= "Bonjour"
content= "This is the fbi. OPEN UP"
message= f"From: {fake_name} <{fake_from}>\nTo: {to_name} <{to_email}>\nSubject: {subject}\n\n{content}"
server = smtplib.SMTP_SSL(mail_server,port, context=ssl.create_default_context())
server.login(username, password)
server.sendmail(username, to_email, message.encode())
server.close()
MIME機能を付加して、日本語・HTMLのメールを送信
通信のデバッグ情報を表示するには server.set_debuglevel(True) を挿入
import smtplib,ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
smtp_host = 'mail.xxx.xxx' #Mailサーバを指定
smtp_port = 465
smtp_account_id = 'hogehoge' #ユーザー名を指定
smtp_account_pass = 'xxxxxxx' #パスワードを入力
from_mail = "hoge <hoge@xxxx.xxx.xx>" # 送信元メールアドレス
to_mail = "HOGE <HOGE@xxxx.xxx>" # 送信先メールアドレス
msg = MIMEMultipart('alternative')
msg['Subject'] = "タイトル" #件名を入力
msg['From'] = from_mail
msg['To'] = to_mail
text = "送信テストです。.nマルチパートで送っています。.nどうですか?"
html = """
<html>
<head></head>
<body>
<p style='font-size:16.0pt;font-family:游ゴシック'>送信テストです。</p>
<p>マルチパートで送っています。</p>
<p>どうですか?</p>
</body>
</html>
"""
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
server = smtplib.SMTP_SSL(smtp_host, smtp_port, context=ssl.create_default_context())
#server.set_debuglevel(True)
server.login(smtp_account_id, smtp_account_pass)
server.sendmail(from_mail, to_mail, msg.as_string())
server.quit()
print('Done.')
10秒間隔で画像を400枚 jpgファイルとして保存
事前にM-JPEG streamerがインストールされ、アドレスxxx.xxx.xxx.xxx:8080で稼働している環境で、ファイル名 T0000.jpgからT0399.jpgとして画像を保存します。
import time
import cv2
# VideoCapture オブジェクトを取得します
URL = "http://xxx.xxx.xxx.xxx:8080/?action=stream"
capture = cv2.VideoCapture(URL)
for n in range(400):
ret, frame = capture.read()
name = "T" + '{:04d}'.format(n)+".jpg"
print(name)
cv2.imwrite(name, frame)
time.sleep(10)
print("Done!")
jpgファイルからmp4動画を生成
import glob
import cv2
img_array = []
for filename in sorted(glob.glob("*.jpg")):
print(filename)
img = cv2.imread(filename)
height, width, layers = img.shape
size = (width, height)
img_array.append(img)
name = 'project.mp4'
out = cv2.VideoWriter(name, cv2.VideoWriter_fourcc(*'mp4v'), 5.0, size)
for i in range(len(img_array)):
out.write(img_array[i])
out.release()
生成したmp4動画の編集(不要部分の削除、回転、再生速度の調整など)には、Windows10標準のソフト「フォト」が便利。
作例