コード例 #1
0
ファイル: test_ses_boto3.py プロジェクト: zatarra/moto
def test_send_raw_email_without_source():
    conn = boto3.client("ses", region_name="us-east-1")

    message = MIMEMultipart()
    message["Subject"] = "Test"
    message["From"] = "*****@*****.**"
    message["To"] = "[email protected], [email protected]"

    # Message body
    part = MIMEText("test file attached")
    message.attach(part)

    # Attachment
    part = MIMEText("contents of test file here")
    part.add_header("Content-Disposition", "attachment; filename=test.txt")
    message.attach(part)

    kwargs = dict(RawMessage={"Data": message.as_string()})

    conn.send_raw_email.when.called_with(**kwargs).should.throw(ClientError)

    conn.verify_email_identity(EmailAddress="*****@*****.**")
    conn.send_raw_email(**kwargs)

    send_quota = conn.get_send_quota()
    sent_count = int(send_quota["SentLast24Hours"])
    sent_count.should.equal(2)
コード例 #2
0
ファイル: UTILS_Envoi_email.py プロジェクト: neoclust/Noethys
 def AttacheFichiersJoints(self, email=None):
     for fichier in self.fichiers:
         """Guess the content type based on the file's extension. Encoding
         will be ignored, altough we should check for simple things like
         gzip'd or compressed files."""
         ctype, encoding = mimetypes.guess_type(fichier)
         if ctype is None or encoding is not None:
             # No guess could be made, or the file is encoded (compresses), so
             # use a generic bag-of-bits type.
             ctype = 'application/octet-stream'
         maintype, subtype = ctype.split('/', 1)
         if maintype == 'text':
             fp = open(fichier)
             # Note : we should handle calculating the charset
             part = MIMEText(fp.read(), _subtype=subtype)
             fp.close()
         elif maintype == 'image':
             fp = open(fichier, 'rb')
             part = MIMEImage(fp.read(), _subtype=subtype)
             fp.close()
         else:
             fp = open(fichier, 'rb')
             part = MIMEBase(maintype, subtype)
             part.set_payload(fp.read())
             fp.close()
             # Encode the payload using Base64
             encoders.encode_base64(part)
         # Set the filename parameter
         nomFichier = os.path.basename(fichier)
         if type(nomFichier) == six.text_type:
             nomFichier = FonctionsPerso.Supprime_accent(nomFichier)
         # changement cosmetique pour ajouter les guillements autour du filename
         part.add_header('Content-Disposition',
                         "attachment; filename=\"%s\"" % nomFichier)
         email.attach(part)
コード例 #3
0
 def AttacheFichiersJoints(self, email=None):
     for fichier in self.fichiers:
         """Guess the content type based on the file's extension. Encoding
         will be ignored, altough we should check for simple things like
         gzip'd or compressed files."""
         ctype, encoding = mimetypes.guess_type(fichier)
         if ctype is None or encoding is not None:
             # No guess could be made, or the file is encoded (compresses), so
             # use a generic bag-of-bits type.
             ctype = 'application/octet-stream'
         maintype, subtype = ctype.split('/', 1)
         if maintype == 'text':
             fp = open(fichier)
             # Note : we should handle calculating the charset
             part = MIMEText(fp.read(), _subtype=subtype)
             fp.close()
         elif maintype == 'image':
             fp = open(fichier, 'rb')
             part = MIMEImage(fp.read(), _subtype=subtype)
             fp.close()
         else:
             fp = open(fichier, 'rb')
             part = MIMEBase(maintype, subtype)
             part.set_payload(fp.read())
             fp.close()
             # Encode the payload using Base64
             encoders.encode_base64(part)
         # Set the filename parameter
         nomFichier = os.path.basename(fichier)
         if type(nomFichier) == six.text_type:
             nomFichier = FonctionsPerso.Supprime_accent(nomFichier)
         # changement cosmetique pour ajouter les guillements autour du filename
         part.add_header('Content-Disposition', "attachment; filename=\"%s\"" % nomFichier)
         email.attach(part)
コード例 #4
0
ファイル: test_ses_boto3.py プロジェクト: botify-labs/moto
def test_send_raw_email_without_source():
    conn = boto3.client('ses', region_name='us-east-1')

    message = MIMEMultipart()
    message['Subject'] = 'Test'
    message['From'] = '*****@*****.**'
    message['To'] = '[email protected], [email protected]'

    # Message body
    part = MIMEText('test file attached')
    message.attach(part)

    # Attachment
    part = MIMEText('contents of test file here')
    part.add_header('Content-Disposition', 'attachment; filename=test.txt')
    message.attach(part)

    kwargs = dict(
        RawMessage={'Data': message.as_string()},
    )

    conn.send_raw_email.when.called_with(**kwargs).should.throw(ClientError)

    conn.verify_email_identity(EmailAddress="*****@*****.**")
    conn.send_raw_email(**kwargs)

    send_quota = conn.get_send_quota()
    sent_count = int(send_quota['SentLast24Hours'])
    sent_count.should.equal(2)
コード例 #5
0
def test_send_raw_email_without_source():
    conn = boto3.client('ses', region_name='us-east-1')

    message = MIMEMultipart()
    message['Subject'] = 'Test'
    message['From'] = '*****@*****.**'
    message['To'] = '[email protected], [email protected]'

    # Message body
    part = MIMEText('test file attached')
    message.attach(part)

    # Attachment
    part = MIMEText('contents of test file here')
    part.add_header('Content-Disposition', 'attachment; filename=test.txt')
    message.attach(part)

    kwargs = dict(RawMessage={'Data': message.as_string()}, )

    conn.send_raw_email.when.called_with(**kwargs).should.throw(ClientError)

    conn.verify_email_identity(EmailAddress="*****@*****.**")
    conn.send_raw_email(**kwargs)

    send_quota = conn.get_send_quota()
    sent_count = int(send_quota['SentLast24Hours'])
    sent_count.should.equal(2)
コード例 #6
0
ファイル: test_ses_boto3.py プロジェクト: zatarra/moto
def get_raw_email():
    message = MIMEMultipart()
    message["Subject"] = "Test"
    message["From"] = "*****@*****.**"
    message["To"] = "[email protected], [email protected]"
    # Message body
    part = MIMEText("test file attached")
    message.attach(part)
    # Attachment
    part = MIMEText("contents of test file here")
    part.add_header("Content-Disposition", "attachment; filename=test.txt")
    message.attach(part)
    return message
コード例 #7
0
ファイル: test_ses_boto3.py プロジェクト: zatarra/moto
def test_send_raw_email_without_source_or_from():
    conn = boto3.client("ses", region_name="us-east-1")

    message = MIMEMultipart()
    message["Subject"] = "Test"
    message["To"] = "[email protected], [email protected]"

    # Message body
    part = MIMEText("test file attached")
    message.attach(part)
    # Attachment
    part = MIMEText("contents of test file here")
    part.add_header("Content-Disposition", "attachment; filename=test.txt")
    message.attach(part)

    kwargs = dict(RawMessage={"Data": message.as_string()})

    conn.send_raw_email.when.called_with(**kwargs).should.throw(ClientError)
コード例 #8
0
def test_send_raw_email_without_source_or_from():
    conn = boto3.client('ses', region_name='us-east-1')

    message = MIMEMultipart()
    message['Subject'] = 'Test'
    message['To'] = '[email protected], [email protected]'

    # Message body
    part = MIMEText('test file attached')
    message.attach(part)
    # Attachment
    part = MIMEText('contents of test file here')
    part.add_header('Content-Disposition', 'attachment; filename=test.txt')
    message.attach(part)

    kwargs = dict(RawMessage={'Data': message.as_string()}, )

    conn.send_raw_email.when.called_with(**kwargs).should.throw(ClientError)
コード例 #9
0
ファイル: test_ses_boto3.py プロジェクト: botify-labs/moto
def test_send_raw_email_without_source_or_from():
    conn = boto3.client('ses', region_name='us-east-1')

    message = MIMEMultipart()
    message['Subject'] = 'Test'
    message['To'] = '[email protected], [email protected]'

    # Message body
    part = MIMEText('test file attached')
    message.attach(part)
    # Attachment
    part = MIMEText('contents of test file here')
    part.add_header('Content-Disposition', 'attachment; filename=test.txt')
    message.attach(part)

    kwargs = dict(
        RawMessage={'Data': message.as_string()},
    )

    conn.send_raw_email.when.called_with(**kwargs).should.throw(ClientError)