flask email service学习笔记-html+图片(补充)

flask email service学习笔记-html+图片(补充)

上篇学习笔记的发送邮件中html正文中的图片是采用在html里面使用base64直接编码图片的方式发送的。
后来发现网易163的企业邮箱不支持这种内嵌的方式。
这里换一种更方便一些的方式。cid:imageName的方式。

视频分享到youtube上了。
https://youtu.be/dS6UVMQaPCI
优酷链接
http://v.youku.com/v_show/id_XMzAyNTk1MzcwOA==.html?f=50944544
GIT地址
https://github.com/aslucky/mailService.git
html模板

<body>
    <header></header>

    <img height="120" width="343" style="text-align:center;margin-left:8%" src="cid:invoice" alt="增值税电子普通发票"/>
    <div>
        <p>尊敬的用户,您好:</p>
        <p><strong>您申请的电子发票已投递成功</strong>,请查收。<br>如您对发票信息有疑问请您联系商家或致电<span>400-xxx-xxxx
</span></p>
        <p>xx电子发票服务</p>
    </div>
</body>

代码修改

# add html content png
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
imgPath = os.path.join(SITE_ROOT, "templates", "invoice.png")

with open(imgPath, 'rb') as fp:
 msg.attach(filename=imgPath, data=fp.read(),
            content_type='application/octet-stream', disposition='inline',
            headers=[('Content-ID', 'invoice')])
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为了实现课程电商网站,我们可以使用Flask框架和MySQL数据库来构建网站,并使用PayPal API来处理付款。以下是一些步骤: 1. 首先,我们需要使用Flask和MySQL来构建网站。我们可以使用Flask的蓝图来组织我们的代码,并使用MySQL来存储我们的数据。 2. 接下来,我们需要使用PayPal API来处理付款。我们可以使用PayPal的Vue.js包装组件vue-paypal-checkout来实现这一点。我们可以将这个组件添加到我们的网站中,并使用它来处理付款。 3. 我们还需要使用python-dotenv和flask-cli自定义命令来管理我们的环境变量和启动我们的应用程序。我们可以使用python-dotenv来加载我们的环境变量,并使用flask-cli自定义命令来启动我们的应用程序。 ```python # 示例代码 from flask import Flask from flask_mysqldb import MySQL from paypalcheckoutsdk.core import PayPalHttpClient, SandboxEnvironment from paypalcheckoutsdk.orders import OrdersCreateRequest app = Flask(__name__) # 配置MySQL数据库 app.config['MYSQL_HOST'] = 'localhost' app.config['MYSQL_USER'] = 'root' app.config['MYSQL_PASSWORD'] = 'password' app.config['MYSQL_DB'] = 'mydatabase' mysql = MySQL(app) # 配置PayPal API client_id = 'YOUR_CLIENT_ID' client_secret = 'YOUR_CLIENT_SECRET' environment = SandboxEnvironment(client_id=client_id, client_secret=client_secret) client = PayPalHttpClient(environment) # 创建订单 request = OrdersCreateRequest() request.prefer('return=representation') request.request_body({ "intent": "CAPTURE", "purchase_units": [{ "amount": { "currency_code": "USD", "value": "100.00" } }] }) response = client.execute(request) print(response.result.id) # 自定义命令 @app.cli.command() def init_db(): cur = mysql.connection.cursor() cur.execute('CREATE TABLE IF NOT EXISTS courses (id INT, name VARCHAR(255), price FLOAT)') mysql.connection.commit() cur.close() print('Initialized the database.') # 蓝图 from flask import Blueprint bp = Blueprint('courses', __name__, url_prefix='/courses') @bp.route('/') def index(): cur = mysql.connection.cursor() cur.execute('SELECT * FROM courses') courses = cur.fetchall() cur.close() return render_template('courses/index.html', courses=courses) @bp.route('/<int:id>') def show(id): cur = mysql.connection.cursor() cur.execute('SELECT * FROM courses WHERE id = %s', [id]) course = cur.fetchone() cur.close() return render_template('courses/show.html', course=course) app.register_blueprint(bp) if __name__ == '__main__': app.run() ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值