golang 发邮件给我
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了golang 发邮件给我相关的知识,希望对你有一定的参考价值。
package main
import (
"flag"
"net/smtp"
"github.com/Sirupsen/logrus"
)
var (
to = flag.String("to", "***********@gmail.com", "To")
subject = flag.String("s", "?", "Subject")
message = flag.String("m", "Hello there!", "Message")
)
func main() {
flag.Parse()
send(*message)
}
func send(body string) {
from := "*@gmail.com"
pass := "******************"
auth := smtp.PlainAuth(*subject, from, pass, "smtp.gmail.com")
msg := []byte("To: " + *to + "\r\n" +
"Subject: " + *subject + "\r\n" +
"\r\n" +
*message + "\r\n")
err := smtp.SendMail("smtp.gmail.com:587",
auth, from, []string{*to}, []byte(msg))
if err != nil {
logrus.Printf("smtp error: %s", err)
return
}
logrus.Print("Mail sent!")
}
python 今天在AFI给我发电子邮件
#!/usr/bin/python3.6
import requests
from bs4 import BeautifulSoup
#Variables
afi_website_url = 'http://www.afi.com/silver/films/calendar.aspx'
mail_sender_service = 'https://api.mailgun.net/v3/sandboxec1e86e70f9641de94f341d840592733.mailgun.org/messages'
mail_sender_service_key = 'key-XXXXXXXXXXXXXXX'
sender = 'Jason <test@test.com>'
recipients = ['test@test.com',]
#Go get the web page
response = requests.get(afi_website_url)
#text comes back ...turn it back into HTML
soup = BeautifulSoup(response.text, 'lxml')
#Get the movies in the today's div
movies = soup.select('.today a')
#The email I'm going to send
email = ''
#This div only contains links to the movies, but I want their descriptions, so loop over each movie
for movie in movies:
#...and get it's URL
url = movie['href'].replace('/silver/films/', '')
#...now go get it
response = requests.get(url)
#text comes back ...turn it back into HTML
soup = BeautifulSoup(response.text, 'lxml')
#Pick out it's title and description and add it to our email
title = soup.select('.film-info .boxout-title')[0]
description = soup.select('.film-info .boxout-blurb')[0]
email += "<a href='{}'>{}</a>{}<br/>".format(url, title, description)
#Now that the email is ready, send it!
response = requests.post(
mail_sender_service,
auth=('api', mail_sender_service_key),
data={
'from': sender,
'to': recipients,
'subject': 'Today\'s movies at the AFI are...',
'html': email
}
)
print('All Done!')
以上是关于golang 发邮件给我的主要内容,如果未能解决你的问题,请参考以下文章