manyuanrong / deno-smtp Goto Github PK
View Code? Open in Web Editor NEWSMTP implements for deno
License: MIT License
SMTP implements for deno
License: MIT License
ror: 451: 4.4.2 Timeout - closing connection. 9sm11874315wmo.34 - gsmtp
I am getting this error after c15 minutes of server start.i found that smtp connection is timing out. the only solution is to restart the server
Dear , author.
First of all, I want to thank you for last upgrading of your package.
Could I ask you to provide a sample example of how to use correctly your package with gmail service, because I ve got an error like:
Socket Error 10061 Connection Refused.
Feel free to close this issue.
Hi!
Like many other third-party libraries, this one also does not yet work with Deno v1.2.x.
I get two errors when I want to run the file with the basic Gmail setup:
error: TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
Type 'URL' is not assignable to type 'string'.
return new URL(url).pathname
~~~
at https://deno.land/[email protected]/path/win32.ts:911:18
TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
Type 'URL' is not assignable to type 'string'.
return new URL(url).pathname;
~~~
at https://deno.land/[email protected]/path/posix.ts:433:18
It seems as if [email protected]
causes the problem.
Maybe you could update the std
library to the version used in Deno v.1.2.x ([email protected]) to fix the issue for people who want to use the latest versions of Deno?
Thank you very much!
Hello, I'm trying to connect my gmail account with gmail smtp but i get this error:
error: Uncaught ConnectionRefused: No connection could be made because the target machine actively refused it. (os error 10061)
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendAsync ($deno$/ops/dispatch_json.ts:98:10)
at async Object.connectTls ($deno$/tls.ts:20:15)
at async SmtpClient.connectTLS (https://deno.land/x/smtp/smtp.ts:36:18)`
Here's the code I use (similar to docs).
import { SmtpClient } from "https://deno.land/x/smtp/mod.ts";
const client = new SmtpClient();
await client.connectTLS({
host: "smtp.gmail.com",
port: 465,
username: "my gmail",
password: "my password",
});
This example was running couple days before and now it gives me an error:
error: Uncaught Error: failed to lookup address information: Name or service not known
at unwrapResponse ($deno$/ops/dispatch_json.ts:43:11)
at Object.sendAsync ($deno$/ops/dispatch_json.ts:98:10)
at async Object.connectTls ($deno$/tls.ts:20:15)
at async SmtpClient.connectTLS (https://deno.land/x/smtp/smtp.ts:36:18)
at async file:///home/pomatti/projects/bizi-infrastructure-code/deno-smtp/deno.ts:13:1
import { SmtpClient } from "https://deno.land/x/smtp/mod.ts";
import { ConnectConfigWithAuthentication } from "https://raw.githubusercontent.com/manyuanrong/deno-smtp/master/config.ts";
const client = new SmtpClient();
const params = <ConnectConfigWithAuthentication>{
hostname: "smtp.google.com",
port: 465,
username: "[email protected]",
password: "pa$$word"
}
await client.connectTLS(params);
await client.send({
from: "[email protected]", // Your Email address
to: "[email protected]", // Email address of the destination
subject: "Mail Title",
content: "Mail Content,maybe HTML",
});
await client.close();
$ deno --version
deno 1.0.3
v8 8.4.300
typescript 3.9.2
Hello,
I got this error when trying to connect.
error: TS2345 [ERROR]: Argument of type
'{ hostname: string; port: number; username: string; password: string; }'
is not assignable to parameter of type 'ConnectConfig'.
Object literal may only specify known properties, and 'username' does not exist in type 'ConnectConfig'.
I'm using this version:
import { SmtpClient } from "https://deno.land/x/smtp@master/mod.ts";
as I saw that some fixed where added. I think what we're missing is the export of the connect config with authentification.
Working fine with my Gmail credentials.
I used the following credentials:
For more port info click here
await client.connectTLS({
hostname: "smtp.office365.com",
port: 587,
username: "***@mydomain.com",
password: "*********"
});
Error:
DenoStdInternalError: bufio: caught error from `readSlice()` without `partial` property
at assert (https://deno.land/[email protected]/_util/assert.ts:13:11)
at BufReader.readLine (https://deno.land/[email protected]/io/bufio.ts:254:7)
at async TextProtoReader.readLineSlice (https://deno.land/[email protected]/textproto/mod.ts:131:17)
at async TextProtoReader.readLine (https://deno.land/[email protected]/textproto/mod.ts:33:15)
at async SmtpClient.readCmd (https://deno.land/x/[email protected]/smtp.ts:151:20)
at async SmtpClient._connect (https://deno.land/x/[email protected]/smtp.ts:118:21)
at async SmtpClient.connectTLS (https://deno.land/x/[email protected]/smtp.ts:68:5)
From what I can tell, there is currently no way to send an email to multiple recipients (other than recreating the client from scratch and resending the email). API-wise, it would be nice to be able to provide a list of strings in to
(cf. e.g. Python's smtplib.sendmail
).
If I'm not mistaken, currently just cover one specific setup: Connection with TLS (as read from ENV) and an email with both text and html content.
If I use the example provided in the README to send an email to an Exchange server, the recipient receives an email with no contents. From a quick look at smtp.ts
, this happens because there's no blank line before the content. Indeed, if I prefix config.content
with an additional \r\n
, the content comes through as expected.
@manyuanrong Deno's registry doesn't allow commit or branch imports anymore (good decision in my opinion). So in order to import from deno.land/x you have to create a version tag/release so we can use it.
To register in the new repository, just follow the instructions in the https://deno.land/x/ landing page, from there on now the process should be automated.
For everyone else, in the meantime you can import from github directly (thanks ECMA for ES modules).
Latest commit as of 03/08/2020
https://raw.githubusercontent.com/manyuanrong/deno-smtp/bc38e10b8fd683f2bca350f2885f64553ab0ea51/mod.ts
import {
SmtpClient
} from "https://raw.githubusercontent.com/manyuanrong/deno-smtp/bc38e10b8fd683f2bca350f2885f64553ab0ea51/mod.ts";
Hi as this project looks dead to me so I created a fork see https://deno.land/x/denomailer wich implements
mimeContent
option)Note until I worked on this I was not familiar with the SMTP protocol so there might be some bugs in it!
Feel free to create issues at my fork and create PR!
The same problem described in this stackoverflow question occurs using AWS SES.
I was able to fix it by adding "+ \r\n"
to the header in smtp.ts
. Will make a PR soon.
Hello Sir thanks for this contribution
Here is my workaround:
import * as base64 from "https://denopkg.com/chiefbiiko/base64/mod.ts";
import { SmtpClient } from "https://deno.land/x/smtp/mod.ts"
const diacritic = 'ça va?'
const b64: string = base64.fromUint8Array(new TextEncoder().encode(diacritic));
console.log(b64)
console.log(btoa(diacritic)) // will not output the same as previous
const to = '[email protected]'
const content = 'content with àccent'
const client = new SmtpClient({ content_encoding: "7bit" })
const subject = `=?utf-8?B?${b64}?=`
const connectConfig: any = { hostname: "in-v3.mailjet.com", port: 465, username: "", password: '' }
await client.connectTLS(connectConfig)
await client.send({ from: '[email protected]', to, subject, content })
await client.close()
console.log('finish')
💡 Note that I had to do the same thing (which is only documented in the official commands of smtp) for the node smtp-client package
await client.connect({
host: "smtp.163.com", // ==> hostname: "smtp.163.com"
port: 25,
username: "username",
password: "password",
});
// ConnectConfig define
export interface ConnectConfig {
hostname: string;
port?: number;
username: string;
password: string;
}
I deploy my project deno in https://dash.deno.com/ after using deno-smtp deploy failed but it work fine in develop environment (localhost).
ConnectionRefused: Connection refused (os error 111)
at async Object.connectTls (deno:ext/net/02_tls.js:37:42)
at async SmtpClient.connectTLS (https://deno.land/x/[email protected]/smtp.ts:35:22)
at async file:///src/core/service/mail/index.ts:5:1
here is the code snippet:
import { SmtpClient } from "https://deno.land/x/smtp/mod.ts";
interface informationMail{
to: string,
subject: string,
text: string,
html: string,
}
const client = new SmtpClient();
await client.connectTLS({
hostname: "smtp.gmail.com",
port: 465,
username: Deno.env.get("EMAIL_DOMAIN"),
password: Deno.env.get("EMAIL_APP_PASSWORD"),
});
export async function sendMail() {
await client.send({
from: Deno.env.get("EMAIL_DOMAIN"),
to: "[email protected]", // list of receivers
subject: "Hello ✔", // Subject line
content: "Hello world?", // plain text body
});
return await client.close();
}
Does anyone know how to solve this problem ?
Thank you
How hard would it be to implement support for upgrading unencrypted connections via the STARTTLS command? Deno seems to include an new unstable API Deno.startTls which in theory should support upgrading connections.
Dear Author,
I'm trying to use your smtp module. But have some problems with connection to Microsoft smtp server.
Thank you for your any support in advance.
I receive message: "InvalidData: received corrupt message"
My configuration for office365 account:
EMAIL_FROM = [email protected] (mylogin and primary e-mail address as well on Office365 with Exchange on-line license)
EMAIL_PWD = my-password
EMAIL_TO = [email protected]
SMTP_SERVER = smtp.office365.com
SMTP_PORT = 587
TLS = true
I've checked with my gmail account - it works perfect. So I assume my code must be correct.
My configuration for gmail:
EMAIL_FROM = [email protected] (mylogin same as my primary e-mail address as well on gmail)
EMAIL_PWD = mypassword
EMAIL_TO = [email protected]
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=465
TLS=true
I've tested postfix as smtp relay to office365 account and sent e-mail from command line. Also works perfect.
So my generally smtp client can connect with office365 and send e-mail.
Any ideas ?
My code:
const client = new SmtpClient();
const { EMAIL_FROM, EMAIL_TO, SMTP_SERVER, SMTP_PORT, TLS, EMAIL_PWD } = config();
const configConnection = {
hostname: SMTP_SERVER,
port: SMTP_PORT ? parseInt(SMTP_PORT) : undefined,
username: EMAIL_FROM,
password: EMAIL_PWD,
};
if (TLS) {
await client.connectTLS(configConnection);
} else {
await client.connect(configConnection);
}
await client.send({
from: EMAIL_FROM,
to: EMAIL_TO,
subject: topic,
content: message,
});
Hi!
I send to a non-existent email and get an error 550:
Uncaught (in promise) Error: 550: Message was not accepted -- invalid mailbox. Local mailbox [email protected] is unavailable: user is terminated
Can I return the object?
for instance:
{
status: 404,
payload: Message was not accepted, invalid mailbox
}
Спасибо!
Hi,
today I had trouble with the username property of ConnectConfig.
I did not find any errors.
Argument of type '{ hostname: string; port: number; username: string; password: string; }' is not assignable to parameter of type 'ConnectConfig'. Object literal may only specify known properties, and 'username' does not exist in type 'ConnectConfig'.ts(2345)
The code:
export const client = new SmtpClient();
await client.connect({
hostname: MAIL_HOST,
port: Number(MAIL_PORT),
username: MAIL_USER,
password: MAIL_PASSWORD,
})
Like the other package when i updated it to Deno v1.4.0, i got error like this
TS1371 [ERROR]: This import is never used as a value and must use 'import type' because the 'importsNotUsedAsValues' is set to 'error'.
import {
^
at https://deno.land/x/[email protected]/smtp.ts:2:1
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
ConnectConfig,
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/mod.ts:2:5
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
ConnectConfigWithAuthentication,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/mod.ts:3:5
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
SendConfig,
~~~~~~~~~~
at https://deno.land/x/[email protected]/mod.ts:4:5
Please fix this by adding Import type and Export type for interface or any other type
Can you please implement?
Hey! First of all, I think we can all agree that this library is great! Thanks for that mate!
One thing that would greatly improve the deno-smtp experience is being able to simply send attachments directly from the client.send method as an array. The attachments could be an object in the base64 + MIME type format, or something similar. I don't know how feasible it would be, but I think it could greatly enhance the deno-smtp experience.
await client.send({
from: my_email,
to: your_email,
subject: "My title",
content: "My content",
attachments: [attachment_1, attachment_2, attachment_3]
});
Thanks for reading!
Hello, first I would like to thanks you for this package for deno.
Works nicely, but I have noticed that part of the read me is not correct. Specifically, the part explaining use case with gmail. Firstly, there is a typo, in line: --hostname: "smtp.gamil.com",--. Secondly, interface ConnectConfig doesnt have a "tls" key (parameter).
Suggestions for the future: I noticed, when sending, I can only send email to only one person. Would be nice to implement possibility to send to multiple people by giving an array.
Again, thank you. Eventhough there is still a way to upgade, it is still a good work.
The API for Deno.dail
has changed (denoland/deno#3000)
According to https://deno.land/typedoc/interfaces/deno.dialoptions.html there is now a DialOptions
object.
// smtp.ts:20:41
this._conn = await Deno.dial({
hostname: config.host,
port: config.port,
transport: "tcp"
});
i can open a PR if you want :)
hostname 写成host
调了又报错 invalid cmd
Hello. First I wanted to say this library is great and working with the latest version of Deno 1.2.3.
I would like to know if you can post an example of how to attach PDF files to the email message using deno?
Thank you!
Not able to use Gmail with valid credentials.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.