0

Googleスプレッドシートにストックされているメールアドレスでメールを送信したい. セルの値を取得できますが、次のようになります:

(<Cell R1C1 'email@gmail.com'>,)
(<Cell R2C1 'email1@gmail.com'>,)
...

MIMEMultipart を使用するには、カンマで区切る必要があります: email@gmail.com,email1gmail.com,...

これは私のコードです:

import gspread
import json
from oauth2client.client import SignedJwtAssertionCredentials
import gdata.spreadsheet.service
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import smtplib

json_key = json.load(open('xxx.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)

wks = gc.open('xxx')
worksheet_id = 'od6'
worksheet = wks.get_worksheet(0)

print worksheet.row_values("A1")

for x in xrange(1,50):
test = "A%s" %x
msg = MIMEMultipart()
msg["To"] = worksheet.acell(test),
print msg["To"]

4

1 に答える 1

0

誰かが解決策を望むなら、私はそれを見つけました:

import gspread
import json
from oauth2client.client import SignedJwtAssertionCredentials
import gdata.spreadsheet.service
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import smtplib

json_key = json.load(open('AUTH2.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
gc = gspread.authorize(credentials)

wks = gc.open('Name-of-your-spreadsheet')
worksheet_id = 'od6'
worksheet = wks.get_worksheet(0)
server = smtplib.SMTP('smtp.gmail.com:25')
server.starttls()
server.login('LOGIN','PSWD')

for x in xrange(1,20):
    getTheCellName = "A%s" %x
    msg = MIMEMultipart()
    getTheCell = worksheet.acell(getTheCellName)
    getTheCellValue = getTheCell.value
    if getTheCellValue != "":
        server.sendmail('Sender-Email',getTheCellValue,'Mail-Content')
于 2015-07-15T07:34:25.213 に答える