node mailer & email bot

email

https://nodemailer.com/about/

https://github.com/nodemailer/nodemailer

https://www.npmjs.com/package/nodemailer

/* eslint no-console: 0 */

'use strict';

const nodemailer = require('../lib/nodemailer');

async function main() {
// Create a SMTP transporter object
let transporter = nodemailer.createTransport({
sendmail: true,
newline: 'windows',
logger: false
}); // Message object
let message = {
from: 'Andris <andris@kreata.ee>', // Comma separated list of recipients
to: 'Andris Reinman <andris.reinman@gmail.com>',
bcc: 'andris@ethereal.email', // Subject of the message
subject: 'Nodemailer is unicode friendly ', // plaintext body
text: 'Hello to myself!', // HTML body
html:
'<p><b>Hello</b> to myself <img src="cid:note@example.com"/></p>' +
'<p>Here\'s a nyan cat for you as an embedded attachment:<br/><img src="cid:nyan@example.com"/></p>', // An array of attachments
attachments: [
// String attachment
{
filename: 'notes.txt',
content: 'Some notes about this e-mail',
contentType: 'text/plain' // optional, would be detected from the filename
}, // Binary Buffer attachment
{
filename: 'image.png',
content: Buffer.from(
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD/' +
'//+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4U' +
'g9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC',
'base64'
), cid: 'note@example.com' // should be as unique as possible
}, // File Stream attachment
{
filename: 'nyan cat .gif',
path: __dirname + '/assets/nyan.gif',
cid: 'nyan@example.com' // should be as unique as possible
}
]
}; let info = await transporter.sendMail(message);
console.log('Message sent successfully as %s', info.messageId);
} main().catch(err => {
console.error(err.message);
process.exit(1);
});

weather api

fetch("https://tianqi.moji.com/weather/china/shanghai/pudong-new-district", { mode: "no-cors", })
.then(res => {
console.log(`res =`, res)
return res.text();
})
.then(html => {
console.log(`html =`, html)
const parser = new DOMParser();
const dom = parser.parseFromString(html, "text/html");
console.log(`html dom =`, dom)
// api data
const todayWeather = dom.querySelectorAll(`.days`)[0].innerText.replace(/[\r\n]/ig, `,`).split(`,`);
// ["今天", "阴", "21° / 30°", "南风", "4-5级", "55 良"]
console.log(`todayWeather api datas =`, todayWeather);
})
.catch(err => {
console.error('Failed to fetch html page content!', err);
});

demo

https://segmentfault.com/a/1190000012251328

https://github.com/growvv/weather-bot

https://github.com/growvv/weather-bot/blob/master/.github/workflows/SendMail.yml

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


node mailer & email bot的更多相关文章

  1. Postman SMTP 存在跨站脚本(XSS)漏洞,请换用Post SMTP Mailer/Email Log

    Postman SMTP 是一个安装量超过10W的WordPress插件,但是已经2年多没有更新,2017年6月29日,被发现存在跨站脚本(XSS)漏洞(查看详情),并且作者一直没有更新,所以被从Wo ...

  2. HCW 19 Team Round (ICPC format) B. Beggin' For A Node(树的重心,交互题)

    B. Beggin' For A Node time limit per test2.0 s memory limit per test256 MB inputstandard input outpu ...

  3. JS打字效果的动态菜单代码分享

    这篇文章主要介绍了JS打字效果的动态菜单,推荐给大家,有需要的小伙伴可以参考下. 这是一款基于javascript实现的打字效果的动态菜单特效代码,分享给大家学习学习. 小提示:浏览器中如果不能正常运 ...

  4. Qt XML读取写入操作

    XML(eXtensible Markup Language,可扩展标记语言)是普通用于数据交换和数据存储的一种多用途文本文件格式: SVG(可标量矢量图形)XML格式,QtSvg模块提供了可用于载入 ...

  5. HDU - 1584 IDA*

    思路:裸的IDA*,估计当前状态至少需要多少距离才能达到目标状态,剪枝即可.每一墩牌只需记录其最上面和最下面的牌型即可完成移动. AC代码 #include <cstdio> #inclu ...

  6. T-codes & Rarely Seen Tables(Updated from previous note)

    T-codes C CO CO01/02/03:Production Order CG CG3Y:Download file from server,never used this before CM ...

  7. prisma 服务器端订阅试用

      graphql 协议是支持数据的实时订阅功能的(一般基于websocket 进行实现) prisma 支持客户端订阅以及服务器端订阅(类似webhook),可以方便将 数据推送后端服务 目的 pr ...

  8. 数据库:XML,解析Dom4J

    package com.itheima.util; import java.io.FileOutputStream; import java.net.URL; import org.dom4j.Doc ...

  9. babeljs源码

    babel.min.js!function(e,t){"object"==typeof exports&&"object"==typeof mo ...

随机推荐

  1. LOJ10199轻拍牛头

    题目描述 原题来自:USACO 2008 Dec. Silver 今天是 Bessie 的生日,并且现在是聚会的游戏时间.Bessie 让编号为 1~N 的 N 头奶牛围成一个圈坐(所以除了最后一头牛 ...

  2. 在 WebAssembly 中实现回调的方式

    本文将介绍在 C++ 中实现 js 回调的几种方式. 在使用 wasm 的过程中, 避免不了要从 C++ 回调 js 的函数来实现异步交互. 官网文档 https://emscripten.org/d ...

  3. Java——定时任务调度工具

    一.什么是定时任务调度? 1.常用的定时调度工具:Timer和Quartz 二.Timer简介 1.Timer的定义以及架构 2.Timer示例 三.Timer的定时调度函数 1.schedule的四 ...

  4. windows下hash抓取的几种方式

    前提:在渗透测试过程中,对于windows系统的机器渗透需要注意hash的获取,其中hash分为LM-HASH与NTLM-HASH,在windows系统中,hash的默认存储位置为: C:\Windo ...

  5. (8)Linux文件目录结构一览表

    1.使用 Linux 时,通过命令行输入 ls -l / 可以看到,在 Linux 根目录(/)下包含很多的子目录(称为一级目录),例如 bin.boot.dev 等.同时,各一级目录下还含有很多子目 ...

  6. I - Swap(交换行列是对角线都为1)

    Given an N*N matrix with each entry equal to 0 or 1. You can swap any two rows or any two columns. C ...

  7. LIS(nlogn)算法描述//线性DP经典类型

    题目描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达捕捉到敌国的导弹 ...

  8. 2020牛客暑期多校训练营(第一场)Easy Integration

    传送门:J. Easy Integration 题意:给你n,求这个积分,最后的结果分子是记为p,分母记为q. 求(p*q-1)mod 998244353. 题解:比赛完看到巨巨说这是贝塔函数,我一搜 ...

  9. Codeforces Round #650 (Div. 3) B. Even Array

    题目链接:https://codeforces.com/contest/1367/problem/B 题意 有一大小为 $n$ 的数组 $a$,问能否经过交换使所有元素与下标奇偶性相同(0 - ind ...

  10. poj3083 Children of the Candy Cor

    Description The cornfield maze is a popular Halloween treat. Visitors are shown the entrance and mus ...