@visulima/email 3.0.27 → 3.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/packem_chunks/index.js +5 -5
- package/dist/packem_shared/{ahaSendProvider-C1qvG8Cj.js → ahaSendProvider-D95-pwFh.js} +1 -1
- package/dist/packem_shared/apply-message-id-nFsQiH5j.js +1 -0
- package/dist/packem_shared/awsSesProvider-DnZo9X_g.js +31 -0
- package/dist/packem_shared/{azureProvider-CLLRKtOf.js → azureProvider-D6Z4c1yT.js} +1 -1
- package/dist/packem_shared/{brevoProvider-CHlodyzV.js → brevoProvider-D1yTSs0l.js} +1 -1
- package/dist/packem_shared/cloudflareEmailProvider-DZbs35NL.js +1 -0
- package/dist/packem_shared/{createTestEmail-sB6z8m6Z.js → createTestEmail-gr512snl.js} +1 -1
- package/dist/packem_shared/{failoverProvider-DSsuXHYK.js → failoverProvider-IED1M0M5.js} +1 -1
- package/dist/packem_shared/generate-message-id-C5AM6DFE.js +1 -0
- package/dist/packem_shared/{httpProvider-CdoJ-tL7.js → httpProvider-CpdWJoRq.js} +1 -1
- package/dist/packem_shared/{infobipProvider-BEu1ycxS.js → infobipProvider-DTqFu5pM.js} +1 -1
- package/dist/packem_shared/{loopsProvider-CKJ_rzLq.js → loopsProvider-PiE2HxoW.js} +1 -1
- package/dist/packem_shared/{mailCrabProvider-BQ5ELwPU.js → mailCrabProvider-BSapw_mS.js} +1 -1
- package/dist/packem_shared/{mailPaceProvider-Ca3cz8JU.js → mailPaceProvider-BugIutTw.js} +1 -1
- package/dist/packem_shared/{mailchannelsProvider-BZeuZk3d.js → mailchannelsProvider-Dn24mI8D.js} +1 -1
- package/dist/packem_shared/{mailerSendProvider-C_Db652T.js → mailerSendProvider-B6X4Lhsf.js} +1 -1
- package/dist/packem_shared/{mailgunProvider-CU2b8ie8.js → mailgunProvider-4sMtcQcW.js} +1 -1
- package/dist/packem_shared/{mailjetProvider-VqvqCS7I.js → mailjetProvider-DvrHwipw.js} +1 -1
- package/dist/packem_shared/{mailomatProvider-FMk4FZZz.js → mailomatProvider-CrkNQGfL.js} +1 -1
- package/dist/packem_shared/{mailtrapProvider-Qs0exKiJ.js → mailtrapProvider-DTgvCUrs.js} +1 -1
- package/dist/packem_shared/{mandrillProvider-Co_EfMxl.js → mandrillProvider-BaK0GEj7.js} +1 -1
- package/dist/packem_shared/{mockProvider-Bf5eJ_rl.js → mockProvider-CTxxbT0d.js} +1 -1
- package/dist/packem_shared/{netcoreProvider-_kXjZ0bE.js → netcoreProvider-BZJ0noQ2.js} +1 -1
- package/dist/packem_shared/{nodemailerProvider-xg9Sh948.js → nodemailerProvider-DqJh8ghN.js} +1 -1
- package/dist/packem_shared/{outlook365Provider-DKMz0Vvh.js → outlook365Provider-DQUSFy2d.js} +1 -1
- package/dist/packem_shared/{plunkProvider-B-JtCJQy.js → plunkProvider-WMi1yPya.js} +1 -1
- package/dist/packem_shared/{postalProvider-tEBNXL3h.js → postalProvider-DpBFGpoX.js} +1 -1
- package/dist/packem_shared/{postmarkProvider-DdavP5x5.js → postmarkProvider-ClUaHPvw.js} +1 -1
- package/dist/packem_shared/{resendProvider-CMtlyIye.js → resendProvider-DtaB7sk0.js} +1 -1
- package/dist/packem_shared/{scalewayProvider-BFA1PQ73.js → scalewayProvider-BhbDUEah.js} +1 -1
- package/dist/packem_shared/{sendGridProvider-DV80Lg7a.js → sendGridProvider-DBZHhxd6.js} +1 -1
- package/dist/packem_shared/smtpProvider-CjcOEiAh.js +14 -0
- package/dist/packem_shared/{sparkpostProvider-C3pATjJX.js → sparkpostProvider-B19lU9D5.js} +1 -1
- package/dist/packem_shared/{sweegoProvider-CkFtUAzq.js → sweegoProvider-H8KWGDff.js} +1 -1
- package/dist/packem_shared/{zeptomailProvider-tqRYpQlv.js → zeptomailProvider-L7nkdn0L.js} +1 -1
- package/dist/providers/ahasend/index.js +1 -1
- package/dist/providers/aws-ses/index.js +1 -1
- package/dist/providers/azure/index.js +1 -1
- package/dist/providers/brevo/index.js +1 -1
- package/dist/providers/cloudflare-email/index.js +1 -1
- package/dist/providers/failover/index.js +1 -1
- package/dist/providers/http/index.js +1 -1
- package/dist/providers/infobip/index.js +1 -1
- package/dist/providers/loops/index.js +1 -1
- package/dist/providers/mailchannels/index.js +1 -1
- package/dist/providers/mailcrab/index.js +1 -1
- package/dist/providers/mailersend/index.js +1 -1
- package/dist/providers/mailgun/index.js +1 -1
- package/dist/providers/mailjet/index.js +1 -1
- package/dist/providers/mailomat/index.js +1 -1
- package/dist/providers/mailpace/index.js +1 -1
- package/dist/providers/mailtrap/index.js +1 -1
- package/dist/providers/mandrill/index.js +1 -1
- package/dist/providers/mock/index.js +1 -1
- package/dist/providers/netcore/index.js +1 -1
- package/dist/providers/nodemailer/index.js +1 -1
- package/dist/providers/outlook365/index.js +1 -1
- package/dist/providers/plunk/index.js +1 -1
- package/dist/providers/postal/index.js +1 -1
- package/dist/providers/postmark/index.js +1 -1
- package/dist/providers/resend/index.js +1 -1
- package/dist/providers/scaleway/index.js +1 -1
- package/dist/providers/sendgrid/index.js +1 -1
- package/dist/providers/smtp/index.js +1 -1
- package/dist/providers/sparkpost/index.js +1 -1
- package/dist/providers/sweego/index.js +1 -1
- package/dist/providers/zeptomail/index.js +1 -1
- package/dist/test/index.js +1 -1
- package/package.json +1 -1
- package/dist/packem_shared/awsSesProvider-DTnLwAbE.js +0 -32
- package/dist/packem_shared/cloudflareEmailProvider-Ckh_u-0D.js +0 -1
- package/dist/packem_shared/generate-message-id-B2n2yqR6.js +0 -1
- package/dist/packem_shared/smtpProvider-BCEzJmay.js +0 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
import l from"./EmailError-BIaHK1Uw.js";import f from"./RequiredOptionError-ctDEEB1s.js";import{g as w}from"./generate-message-id-
|
|
1
|
+
import l from"./EmailError-BIaHK1Uw.js";import f from"./RequiredOptionError-ctDEEB1s.js";import{g as w}from"./generate-message-id-C5AM6DFE.js";import{h as v}from"./headers-to-record-ZOZ7Dubo.js";import{m as y}from"./make-request-Cyz5_yu8.js";import{r as g}from"./retry-aghj7y8m.js";import{v as E}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as I}from"./defineProvider-C9q-7iwt.js";import{c as T,P as A,h}from"./provider-base-BEz00m9R.js";import{f as u,a as P}from"./address-formatter-w36S9ZYj.js";import{p as S}from"./attachment-processor-BJFDS343.js";const t="scaleway",j="https://api.scaleway.com/transactional-email/v1alpha1",R=3e4,k=3,G=I((a={})=>{if(!a.apiKey)throw new f(t,"apiKey");if(!a.region)throw new f(t,"region");const p=a.endpoint??j,s={apiKey:a.apiKey,debug:a.debug??!1,endpoint:p,region:a.region,retries:a.retries??k,timeout:a.timeout??R,...a.logger&&{logger:a.logger}},d=new A,i=T(t,a.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!0,tracking:!1},async getEmail(e){try{if(!e)return{error:new l(t,"Email ID is required to retrieve email details"),success:!1};await d.ensureInitialized(()=>this.initialize(),t);const o={"Content-Type":"application/json","X-Auth-Token":s.apiKey};i.debug("Retrieving email details",{id:e});const r=await g(async()=>y(`${s.endpoint}/regions/${s.region}/emails/${e}`,{headers:o,method:"GET",timeout:s.timeout}),s.retries);return r.success?(i.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(i.debug("API request failed when retrieving email",r.error),{error:new l(t,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:h(t,"retrieve email",o,i),success:!1}}},async initialize(){await d.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(t,"Scaleway API not available or invalid API key");i.debug("Provider initialized successfully")},t)},async isAvailable(){try{return i.debug("Checking Scaleway API availability"),!0}catch(e){return i.debug("Error checking availability:",e),!1}},name:t,options:s,async sendEmail(e){try{const o=E(e);if(o.length>0)return{error:new l(t,`Invalid email options: ${o.join(", ")}`),success:!1};await d.ensureInitialized(()=>this.initialize(),t);const r={from:{email:e.from.email,...e.from.name&&{name:e.from.name}},subject:e.subject,to:u(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=u(e.cc)),e.bcc&&(r.bcc=u(e.bcc)),e.replyTo&&(r.replyTo=P(e.replyTo)),e.templateId&&(r.templateId=e.templateId,e.templateVariables&&(r.templateVariables=e.templateVariables)),e.projectId&&(r.projectId=e.projectId),e.headers){const c=v(e.headers);r.headers=c}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async c=>({content:await S(c,t),name:c.filename,type:c.contentType??"application/octet-stream"})))),i.debug("Sending email via Scaleway API",{subject:r.subject,to:r.to});const b={"Content-Type":"application/json","X-Auth-Token":s.apiKey},n=await g(async()=>y(`${s.endpoint}/regions/${s.region}/emails`,{headers:b,method:"POST",timeout:s.timeout},JSON.stringify(r)),s.retries);if(!n.success)return i.debug("API request failed when sending email",n.error),{error:n.error??new l(t,"Failed to send email"),success:!1};const m=n.data?.body?.id??w();return i.debug("Email sent successfully",{messageId:m}),{data:{messageId:m,provider:t,response:n.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:h(t,"send email",o,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{G as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import u from"./EmailError-BIaHK1Uw.js";import E from"./RequiredOptionError-ctDEEB1s.js";import{g as w}from"./generate-message-id-
|
|
1
|
+
import u from"./EmailError-BIaHK1Uw.js";import E from"./RequiredOptionError-ctDEEB1s.js";import{g as w}from"./generate-message-id-C5AM6DFE.js";import{h as P}from"./headers-to-record-ZOZ7Dubo.js";import{m as h}from"./make-request-Cyz5_yu8.js";import{r as p}from"./retry-aghj7y8m.js";import{v as S}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as T}from"./defineProvider-C9q-7iwt.js";import{c as G,P as _,h as v}from"./provider-base-BEz00m9R.js";import{f as y,a as I}from"./address-formatter-w36S9ZYj.js";import{d as j}from"./attachment-processor-BJFDS343.js";const s="sendgrid",z="https://api.sendgrid.com/v3",k=3e4,C=3,H=T((o={})=>{if(!o.apiKey)throw new E(s,"apiKey");const r={apiKey:o.apiKey,debug:o.debug??!1,endpoint:o.endpoint??z,...o.logger&&{logger:o.logger},retries:o.retries??C,timeout:o.timeout??k},f=new _,i=G(s,o.logger);return{endpoint:r.endpoint,features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!0,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new u(s,"Email ID is required to retrieve email details"),success:!1};await f.ensureInitialized(()=>this.initialize(),s);const t={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};i.debug("Retrieving email details",{id:e});const a=await p(async()=>h(`${r.endpoint}/messages/${e}`,{headers:t,method:"GET",timeout:r.timeout}),r.retries);return a.success?(i.debug("Email details retrieved successfully"),{data:a.data?.body,success:!0}):(i.debug("API request failed when retrieving email",a.error),{error:new u(s,`Failed to retrieve email: ${a.error instanceof Error?a.error.message:"Unknown error"}`,{cause:a.error}),success:!1})}catch(t){return{error:v(s,"retrieve email",t,i),success:!1}}},async initialize(){await f.ensureInitialized(async()=>{if(!await this.isAvailable())throw new u(s,"SendGrid API not available or invalid API key");i.debug("Provider initialized successfully")},s)},async isAvailable(){try{if(r.apiKey&&r.apiKey.startsWith("SG."))return i.debug("API key format is valid, assuming SendGrid is available"),!0;const e={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"};i.debug("Checking SendGrid API availability");const t=await h(`${r.endpoint}/user/profile`,{headers:e,method:"GET",timeout:r.timeout});return i.debug("SendGrid API availability check response:",{error:t.error instanceof Error?t.error.message:void 0,statusCode:t.data?.statusCode,success:t.success}),!!(t.success&&t.data&&typeof t.data=="object"&&"statusCode"in t.data&&typeof t.data.statusCode=="number"&&t.data.statusCode>=200&&t.data.statusCode<300)}catch(e){return i.debug("Error checking availability:",e),!1}},name:s,options:r,async sendEmail(e){try{const t=S(e);if(t.length>0)return{error:new u(s,`Invalid email options: ${t.join(", ")}`),success:!1};await f.ensureInitialized(()=>this.initialize(),s);const a={to:y(e.to)};if(e.cc&&(a.cc=y(e.cc)),e.bcc&&(a.bcc=y(e.bcc)),e.subject&&(a.subject=e.subject),e.tags&&e.tags.length>0){const n={};for(let g=0;g<e.tags.length;g+=1)n[`tag_${g}`]=e.tags[g];a.customArgs=n}const d={from:I(e.from),personalizations:[a]},l=[];if(e.html&&l.push({type:"text/html",value:e.html}),e.text&&l.push({type:"text/plain",value:e.text}),l.length>0&&(d.content=l),e.replyTo&&(d.reply_to=I(e.replyTo)),e.subject&&(d.subject=e.subject),e.templateId&&(d.template_id=e.templateId,e.templateData&&(a.dynamicTemplateData=e.templateData)),e.sendAt&&(a.send_at=e.sendAt),e.batchId&&(d.batch_id=e.batchId),e.asmGroupId&&(d.asm={group_id:e.asmGroupId}),e.ipPoolName&&(d.ip_pool_name=e.ipPoolName),e.mailSettings&&(d.mail_settings=e.mailSettings),e.trackingSettings&&(d.tracking_settings=e.trackingSettings),e.headers){const n=P(e.headers);d.headers=n}e.attachments&&e.attachments.length>0&&(d.attachments=await Promise.all(e.attachments.map(async n=>j(n,s)))),i.debug("Sending email via SendGrid API",{subject:d.subject,to:a.to});const A={Authorization:`Bearer ${r.apiKey}`,"Content-Type":"application/json"},c=await p(async()=>h(`${r.endpoint}/mail/send`,{headers:A,method:"POST",timeout:r.timeout},JSON.stringify(d)),r.retries);if(!c.success)return i.debug("API request failed when sending email",c.error),{error:c.error??new u(s,"Failed to send email"),success:!1};const m=c.data?.headers,b=(m&&m instanceof Headers?m.get("X-Message-Id"):void 0)??w();return i.debug("Email sent successfully",{messageId:b}),{data:{messageId:b,provider:s,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(t){return{error:v(s,"send email",t,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{H as default};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import{createRequire as x}from"node:module";import{createTransportDkimSigner as W}from"./DkimSigner-CCxFKitN.js";import f from"./EmailError-BIaHK1Uw.js";import Y from"./RequiredOptionError-ctDEEB1s.js";import{a as Q}from"./apply-message-id-nFsQiH5j.js";import{b as K}from"./build-mime-message-BCFKPqaW.js";import{v as J}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as O}from"./defineProvider-C9q-7iwt.js";let q;const G=d=>(q??=x(import.meta.url))(d),M=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,U=d=>{if(typeof M<"u"&&M.versions&&M.versions.node){const[t,A]=M.versions.node.split(".").map(Number);if(t>22||t===22&&A>=3||t===20&&A>=16)return M.getBuiltinModule(d)}return G(d)},{Buffer:E}=U("node:buffer"),{createHmac:B}=U("node:crypto"),{Socket:X,createConnection:V}=U("node:net"),{connect:H}=U("node:tls"),Z=(d,t)=>new Promise(A=>{const w=new X,g=()=>{w.destroy(),A(!1)};w.setTimeout(1e3),w.on("error",g),w.on("timeout",g),w.connect(t,d,()=>{w.end(),A(!0)})}),l="smtp",ee=25,te=465,re=1e4,se=!1,oe=5,N=3e4,ae=/^\./,pe=O((d={})=>{if(!d.host)throw new Y(l,"host");const t={authMethod:d.authMethod??"LOGIN",debug:d.debug??!1,dkim:d.dkim,host:d.host,maxConnections:d.maxConnections??oe,oauth2:d.oauth2,password:d.password,pool:d.pool??!1,port:d.port!==void 0?d.port:d.secure?te:ee,rejectUnauthorized:d.rejectUnauthorized??!0,retries:d.retries??0,secure:d.secure??se,timeout:d.timeout??re,user:d.user,...d.logger&&{logger:d.logger}};let A=!1;const w=[],g=[];let R=0;const j=()=>{R+=1},v=()=>{R>0&&(R-=1)},$=e=>e.replaceAll(/[\r\n\t\v\f]/g," ").trim(),I=e=>{const a=e.split(`\r
|
|
2
|
+
`),o={};for(const n of a)if(n.startsWith("250-")||n.startsWith("250 ")){const i=n.slice(4).trim().split(" "),s=i[0];s&&(o[s]=i.slice(1))}return o},h=async(e,a,o)=>new Promise((n,c)=>{const i=Array.isArray(o)?o:[o];let s="",u="";const y=setTimeout(()=>{m(),c(new f(l,`Command timeout after ${t.timeout}ms: ${a?.slice(0,50)}...`))},t.timeout),m=()=>{e.removeListener("data",p),e.removeListener("error",S),y&&clearTimeout(y)},p=r=>{s+=r.toString();const T=s.split(`\r
|
|
3
|
+
`).filter(Boolean);if(T.length>0){const L=T.at(-1);if(L){const _=L.match(/^(\d{3})[\s-]/);if(_){const[,z]=_;u=z,L[3]===" "&&(m(),i.includes(u)?n(s):c(new f(l,`Expected ${i.join(" or ")}, got ${u}: ${s.trim()}`)))}}}},S=r=>{m(),c(new f(l,`Socket error: ${r.message}`,{cause:r}))};e.on("data",p),e.on("error",S),a&&e.write(`${a}\r
|
|
4
|
+
`)}),C=async()=>{if(t.pool&&w.length>0){const e=w.pop();if(e&&!e.destroyed)return e;e&&v()}return t.pool&&R>=t.maxConnections?new Promise((e,a)=>{const o={reject:a,resolve:e};o.timeout=setTimeout(()=>{const n=g.indexOf(o);n!==-1&&g.splice(n,1),a(new f(l,`Connection queue timeout after ${N}ms`))},N),g.push(o)}):new Promise((e,a)=>{let o,n=!1,c;const i=()=>{o&&clearTimeout(o)};o=setTimeout(()=>{n||(n=!0,c&&!c.destroyed&&c.destroy(),i(),a(new f(l,`Connection timeout to ${t.host}:${t.port} after ${t.timeout}ms`)))},t.timeout);try{c=t.secure?H({host:t.host,port:t.port,rejectUnauthorized:t.rejectUnauthorized}):V(t.port,t.host),c.on("error",s=>{n||(n=!0,i(),a(new f(l,`Connection error: ${s.message}`,{cause:s})))}),c.once("data",s=>{if(!n&&c){n=!0,i();const u=s.toString();u.slice(0,3)==="220"?(j(),e(c)):(c.destroy(),a(new f(l,`Unexpected server greeting: ${u.trim()}`)))}})}catch(s){n||(n=!0,i(),a(new f(l,`Failed to create connection: ${s.message}`,{cause:s})))}})},P=async e=>new Promise((a,o)=>{let n,c=!1,i;const s=()=>{n&&clearTimeout(n)};n=setTimeout(()=>{c||(c=!0,i&&!i.destroyed&&i.destroy(),s(),o(new f(l,`TLS connection timeout after ${t.timeout}ms`)))},t.timeout);try{const u={host:t.host,rejectUnauthorized:t.rejectUnauthorized,socket:e};i=H(u),i.on("error",y=>{c||(c=!0,s(),o(new f(l,`TLS connection error: ${y.message}`,{cause:y})))}),i.once("secure",()=>{!c&&i&&(c=!0,s(),a(i))})}catch(u){c||(c=!0,s(),o(new f(l,`Failed to upgrade to TLS: ${u.message}`,{cause:u})))}}),k=e=>{if(e.destroyed||!t.pool){try{e.destroy()}catch{}v();return}if(g.length>0){const a=g.shift();if(a){clearTimeout(a.timeout),a.resolve(e);return}}w.push(e)},b=async(e,a=!1)=>{if(a){if(!e.destroyed)try{await h(e,"RSET","250")}catch{e.destroy()}k(e);return}await new Promise(o=>{try{v(),e.write(`QUIT\r
|
|
5
|
+
`),e.end(),e.once("close",()=>{o()})}catch{o()}})},D=async e=>{if(!t.user)return;const a=await h(e,`EHLO ${t.host}`,"250"),o=I(a),n=Object.keys(o).find(s=>s.toUpperCase()==="AUTH");if(!n&&(t.user||t.password))throw new f(l,"Server does not support authentication");const c=n?o[n]??[]:[];let{authMethod:i}=t;if(i||(c.includes("CRAM-MD5")?i="CRAM-MD5":c.includes("LOGIN")?i="LOGIN":c.includes("PLAIN")&&(i="PLAIN")),!i)throw new f(l,"No supported authentication methods");if(i==="OAUTH2"&&t.oauth2)try{const{accessToken:s,user:u}=t.oauth2,y=`user=${u}auth=Bearer ${s}`,m=E.from(y).toString("base64");await h(e,`AUTH XOAUTH2 ${m}`,"235");return}catch(s){const u=s.message;throw u.includes("535")||u.includes("Authentication failed")?new f(l,"Authentication failed: Invalid OAuth2 credentials"):s}if(i==="CRAM-MD5"&&t.password)try{const u=(await h(e,"AUTH CRAM-MD5","334")).split(" ")[1];if(!u)throw new f(l,"Invalid CRAM-MD5 challenge response");const y=E.from(u,"base64").toString("utf8"),m=B("md5",t.password);m.update(y);const p=m.digest("hex"),S=`${t.user} ${p}`;await h(e,E.from(S).toString("base64"),"235");return}catch(s){const u=s.message;throw u.includes("535")||u.includes("Authentication failed")?new f(l,"Authentication failed: Invalid username or password"):s}if(i==="LOGIN"&&t.password)try{await h(e,"AUTH LOGIN","334"),await h(e,E.from(t.user).toString("base64"),"334"),await h(e,E.from(t.password).toString("base64"),"235");return}catch(s){const u=s.message;throw u.includes("535")||u.includes("Authentication failed")?new f(l,"Authentication failed: Invalid username or password"):s}if(i==="PLAIN"&&t.password)try{const s=E.from(`\0${t.user}\0${t.password}`).toString("base64");await h(e,`AUTH PLAIN ${s}`,"235");return}catch(s){const u=s.message;throw u.includes("535")||u.includes("Authentication failed")?new f(l,"Authentication failed: Invalid username or password"):s}throw new f(l,"Authentication failed - no valid credentials or method")},F=async e=>{if(!t.dkim)return e;try{return await W(t.dkim).signMimeMessage(e)}catch(a){throw new f(l,`DKIM signing failed: ${a.message}`)}};return{features:{attachments:!0,batchSending:t.pool,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){if(!A)try{if(!await this.isAvailable())throw new f(l,`SMTP server not available at ${t.host}:${t.port}`);A=!0}catch(e){throw new f(l,`Failed to initialize: ${e.message}`,{cause:e})}},async isAvailable(){try{if(!await Z(t.host,t.port))return!1;const a=await C();return await b(a),!0}catch{return!1}},name:l,options:t,async sendEmail(e){try{const a=J(e);if(a.length>0)return{error:new f(l,`Invalid email options: ${a.join(", ")}`),success:!1};A||await this.initialize();let o=await C();try{let n=I(await h(o,`EHLO ${t.host}`,"250"));if(!t.secure)try{const r=await h(o,`EHLO ${t.host}`,"250"),T=I(r);n=T,Object.keys(T).includes("STARTTLS")&&(await h(o,"STARTTLS","220"),o=await P(o),n=I(await h(o,`EHLO ${t.host}`,"250")))}catch(r){if(t.rejectUnauthorized)throw new f(l,`STARTTLS failed or not supported: ${r.message}`,{cause:r})}await D(o);const c=Object.keys(n).some(r=>r.toUpperCase()==="DSN");let i="";if(e.dsn&&c){const r=[];e.dsn.success&&r.push("SUCCESS"),e.dsn.failure&&r.push("FAILURE"),e.dsn.delay&&r.push("DELAY"),r.length>0&&(i=` NOTIFY=${r.join(",")}`)}await h(o,`MAIL FROM:<${e.from.email}>`,"250");const s=[];Array.isArray(e.to)?s.push(...e.to.map(r=>r.email)):s.push(e.to.email),e.cc&&(Array.isArray(e.cc)?s.push(...e.cc.map(r=>r.email)):s.push(e.cc.email)),e.bcc&&(Array.isArray(e.bcc)?s.push(...e.bcc.map(r=>r.email)):s.push(e.bcc.email));for(const r of s)await h(o,`RCPT TO:<${r}>${i}`,"250");await h(o,"DATA","354");const{headers:u,messageId:y}=Q(e);let m=await K({...e,headers:u});const p=[];if(e.dsn&&!c){const r=[];e.dsn.success&&r.push("SUCCESS"),e.dsn.failure&&r.push("FAILURE"),e.dsn.delay&&r.push("DELAY"),r.length>0&&p.push(`X-DSN-NOTIFY: ${r.join(",")}`)}if(e.priority){let r="";switch(e.priority){case"high":{r="1 (Highest)",p.push("Importance: High");break}case"low":{r="5 (Lowest)",p.push("Importance: Low");break}case"normal":{r="3 (Normal)",p.push("Importance: Normal");break}default:{r="3 (Normal)";break}}p.push(`X-Priority: ${r}`)}if(e.inReplyTo&&p.push(`In-Reply-To: ${$(e.inReplyTo)}`),e.references){const r=Array.isArray(e.references)?e.references.map(T=>$(T)).join(" "):$(e.references);p.push(`References: ${r}`)}if(e.listUnsubscribe){const r=Array.isArray(e.listUnsubscribe)?e.listUnsubscribe.map(T=>`<${$(T)}>`).join(", "):`<${$(e.listUnsubscribe)}>`;p.push(`List-Unsubscribe: ${r}`)}if(e.googleMailHeaders){const{googleMailHeaders:r}=e;r.feedbackId&&p.push(`Feedback-ID: ${$(r.feedbackId)}`),r.promotionalContent&&p.push("X-Google-Promotion: promotional"),r.category&&p.push(`X-Gmail-Labels: ${r.category}`)}if(p.length>0){const r=m.indexOf(`\r
|
|
6
|
+
\r
|
|
7
|
+
`);if(r!==-1){const T=m.slice(0,r),L=m.slice(r+4);m=`${T}\r
|
|
8
|
+
${p.join(`\r
|
|
9
|
+
`)}\r
|
|
10
|
+
\r
|
|
11
|
+
${L}`}}t.dkim&&(e.useDkim||e.useDkim===void 0)&&(m=await F(m));const S=m.replaceAll(`\r
|
|
12
|
+
.`,`\r
|
|
13
|
+
..`).replace(ae,"..");return await h(o,`${S}\r
|
|
14
|
+
.`,"250"),await b(o,t.pool),{data:{messageId:y,provider:l,response:"Message accepted",sent:!0,timestamp:new Date},success:!0}}catch(n){try{await b(o)}catch{}throw n}}catch(a){return{error:new f(l,`Failed to send email: ${a.message}`,{cause:a}),success:!1}}},async shutdown(){for(const e of w)try{await b(e)}catch{}w.length=0;for(const e of g)clearTimeout(e.timeout),e.reject(new Error("Provider shutdown"));g.length=0},async validateCredentials(){try{if(!await this.isAvailable())return!1;let e=await C();try{if(await h(e,`EHLO ${t.host}`,"250"),!t.secure)try{const a=await h(e,`EHLO ${t.host}`,"250"),o=I(a);Object.keys(o).includes("STARTTLS")&&(await h(e,"STARTTLS","220"),e=await P(e),await h(e,`EHLO ${t.host}`,"250"))}catch{if(t.rejectUnauthorized)return await b(e),!1}return await D(e),await b(e),!0}catch{return await b(e),!1}}catch{return!1}}}});export{pe as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import h from"./EmailError-BIaHK1Uw.js";import A from"./RequiredOptionError-ctDEEB1s.js";import{g as E}from"./generate-message-id-
|
|
1
|
+
import h from"./EmailError-BIaHK1Uw.js";import A from"./RequiredOptionError-ctDEEB1s.js";import{g as E}from"./generate-message-id-C5AM6DFE.js";import{m as I}from"./make-request-Cyz5_yu8.js";import{r as w}from"./retry-aghj7y8m.js";import{v as P}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as T}from"./defineProvider-C9q-7iwt.js";import{c as _,P as S,h as j}from"./provider-base-BEz00m9R.js";import{a as u}from"./address-formatter-w36S9ZYj.js";import{c as z}from"./attachment-processor-BJFDS343.js";const r="sparkpost",C="https://api.sparkpost.com/api/v1",D=3e4,K=3,m=a=>[a].flat(),J=T((a={})=>{if(!a.apiKey)throw new A(r,"apiKey");const o={apiKey:a.apiKey,debug:a.debug??!1,endpoint:a.endpoint??C,logger:a.logger,retries:a.retries??K,timeout:a.timeout??D},y=new S,g=_(r,a.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async initialize(){await y.ensureInitialized(async()=>{if(!await this.isAvailable())throw new h(r,"SparkPost API not available or invalid API key");g.debug("Provider initialized successfully")},r)},async isAvailable(){return o.apiKey.length>0},name:r,options:o,async sendEmail(e){try{const i=P(e);if(i.length>0)return{error:new h(r,`Invalid email options: ${i.join(", ")}`),success:!1};await y.ensureInitialized(()=>this.initialize(),r);const l=m(e.to),p=e.cc?m(e.cc):[],v=e.bcc?m(e.bcc):[],k=[...l.map(t=>({address:u(t)})),...p.map(t=>({address:{...u(t),header_to:l.map(s=>s.email).join(", ")}})),...v.map(t=>({address:{...u(t),header_to:l.map(s=>s.email).join(", ")}}))],n={from:u(e.from),subject:e.subject};if(e.html&&(n.html=e.html),e.text&&(n.text=e.text),e.replyTo){const t=m(e.replyTo)[0];t&&(n.reply_to=t.email)}const c={};if(p.length>0&&(c.CC=p.map(t=>t.email).join(", ")),e.headers)for(const[t,s]of Object.entries(e.headers))c[t]=String(s);Object.keys(c).length>0&&(n.headers=c),e.templateId&&(n.template_id=e.templateId),e.attachments&&e.attachments.length>0&&(n.attachments=await Promise.all(e.attachments.map(async t=>{const s=await z(t,r);return{data:s.content,name:s.filename,type:s.contentType}})));const f={content:n,recipients:k};e.campaignId&&(f.campaign_id=e.campaignId),(e.trackOpens!==void 0||e.trackClicks!==void 0)&&(f.options={click_tracking:e.trackClicks??!0,open_tracking:e.trackOpens??!0});const d=await w(async()=>I(`${o.endpoint}/transmissions`,{headers:{Authorization:o.apiKey,"Content-Type":"application/json"},method:"POST",timeout:o.timeout},JSON.stringify(f)),o.retries);if(!d.success)return{error:d.error??new h(r,"Failed to send email"),success:!1};const{body:b}=d.data;return{data:{messageId:b?.results?.id??E(),provider:r,response:d.data,sent:!0,timestamp:new Date},success:!0}}catch(i){return{error:j(r,"send email",i,g),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{J as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import d from"./EmailError-BIaHK1Uw.js";import b from"./RequiredOptionError-ctDEEB1s.js";import{g as v}from"./generate-message-id-
|
|
1
|
+
import d from"./EmailError-BIaHK1Uw.js";import b from"./RequiredOptionError-ctDEEB1s.js";import{g as v}from"./generate-message-id-C5AM6DFE.js";import{h as w}from"./headers-to-record-ZOZ7Dubo.js";import{m as f}from"./make-request-Cyz5_yu8.js";import{r as h}from"./retry-aghj7y8m.js";import{v as E}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as I}from"./defineProvider-C9q-7iwt.js";import{c as A,P as T,h as y}from"./provider-base-BEz00m9R.js";import{f as u,a as P}from"./address-formatter-w36S9ZYj.js";import{p as S}from"./attachment-processor-BJFDS343.js";const t="sweego",z="https://api.sweego.com",R=3e4,j=3,_=I((s={})=>{if(!s.apiKey)throw new b(t,"apiKey");const i={apiKey:s.apiKey,debug:s.debug??!1,endpoint:s.endpoint??z,retries:s.retries??j,timeout:s.timeout??R,...s.logger&&{logger:s.logger}},l=new T,a=A(t,s.logger);return{features:{attachments:!0,batchSending:!0,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!0,templates:!0,tracking:!0},async getEmail(e){try{if(!e)return{error:new d(t,"Email ID is required to retrieve email details"),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const o={Authorization:`Bearer ${i.apiKey}`,"Content-Type":"application/json"};a.debug("Retrieving email details",{id:e});const r=await h(async()=>f(`${i.endpoint}/emails/${e}`,{headers:o,method:"GET",timeout:i.timeout}),i.retries);return r.success?(a.debug("Email details retrieved successfully"),{data:r.data?.body,success:!0}):(a.debug("API request failed when retrieving email",r.error),{error:new d(t,`Failed to retrieve email: ${r.error instanceof Error?r.error.message:"Unknown error"}`,{cause:r.error}),success:!1})}catch(o){return{error:y(t,"retrieve email",o,a),success:!1}}},async initialize(){await l.ensureInitialized(async()=>{if(!await this.isAvailable())throw new d(t,"Sweego API not available or invalid API key");a.debug("Provider initialized successfully")},t)},async isAvailable(){try{return a.debug("Checking Sweego API availability"),!0}catch(e){return a.debug("Error checking availability:",e),!1}},name:t,options:i,async sendEmail(e){try{const o=E(e);if(o.length>0)return{error:new d(t,`Invalid email options: ${o.join(", ")}`),success:!1};await l.ensureInitialized(()=>this.initialize(),t);const r={from:{email:e.from.email,name:e.from.name},subject:e.subject,to:u(e.to)};if(e.html&&(r.html=e.html),e.text&&(r.text=e.text),e.cc&&(r.cc=u(e.cc)),e.bcc&&(r.bcc=u(e.bcc)),e.replyTo&&(r.replyTo=P(e.replyTo)),e.templateId&&(r.templateId=e.templateId,e.templateVariables&&(r.templateVariables=e.templateVariables)),e.tags&&e.tags.length>0&&(r.tags=e.tags),e.headers){const n=w(e.headers);r.headers=n}e.attachments&&e.attachments.length>0&&(r.attachments=await Promise.all(e.attachments.map(async n=>({content:await S(n,t),contentType:n.contentType??"application/octet-stream",filename:n.filename,...n.cid&&{cid:n.cid}})))),a.debug("Sending email via Sweego API",{subject:r.subject,to:r.to});const p={Authorization:`Bearer ${i.apiKey}`,"Content-Type":"application/json"},c=await h(async()=>f(`${i.endpoint}/send`,{headers:p,method:"POST",timeout:i.timeout},JSON.stringify(r)),i.retries);if(!c.success)return a.debug("API request failed when sending email",c.error),{error:c.error??new d(t,"Failed to send email"),success:!1};const m=c.data?.body,g=m?.messageId??m?.id??v();return a.debug("Email sent successfully",{messageId:g}),{data:{messageId:g,provider:t,response:c.data,sent:!0,timestamp:new Date},success:!0}}catch(o){return{error:y(t,"send email",o,a),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{_ as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import l from"./EmailError-BIaHK1Uw.js";import g from"./RequiredOptionError-ctDEEB1s.js";import{g as k}from"./generate-message-id-
|
|
1
|
+
import l from"./EmailError-BIaHK1Uw.js";import g from"./RequiredOptionError-ctDEEB1s.js";import{g as k}from"./generate-message-id-C5AM6DFE.js";import{h as v}from"./headers-to-record-ZOZ7Dubo.js";import{m as p}from"./make-request-Cyz5_yu8.js";import{r as E}from"./retry-aghj7y8m.js";import{s as A,a as _}from"./sanitize-header-CW0f3IT7.js";import{v as T}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as w}from"./defineProvider-C9q-7iwt.js";import{c as z,P,h as I}from"./provider-base-BEz00m9R.js";import{n as y}from"./address-formatter-w36S9ZYj.js";const s="zeptomail",j="https://api.zeptomail.com/v1.1",D=3e4,R=3,M=w((o={})=>{if(!o.token)throw new g(s,"token");if(!o.token.startsWith("Zoho-enczapikey "))throw new l(s,'Token should be in the format "Zoho-enczapikey <your_api_key>"');const c={debug:o.debug??!1,endpoint:o.endpoint??j,logger:o.logger,retries:o.retries??R,timeout:o.timeout??D,token:o.token},u=new P,i=z(s,o.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!0},async initialize(){await u.ensureInitialized(async()=>{if(!await this.isAvailable())throw new l(s,"Zeptomail API not available or invalid token");i.debug("Provider initialized successfully")},s)},async isAvailable(){try{return c.token&&c.token.startsWith("Zoho-enczapikey ")?(i.debug("Token format is valid, assuming Zeptomail is available"),!0):!1}catch(e){return i.debug("Error checking availability:",e),!1}},name:s,options:c,async sendEmail(e){try{const d=T(e);if(d.length>0)return{error:new l(s,`Invalid email options: ${d.join(", ")}`),success:!1};await u.ensureInitialized(()=>this.initialize(),s);const t={from:y(e.from).address,subject:e.subject};if(Array.isArray(e.to)?t.to=e.to.length===1?e.to[0].email:e.to.map(r=>r.email):t.to=e.to.email,e.text&&(t.textbody=e.text),e.html&&(t.htmlbody=e.html),e.cc&&(Array.isArray(e.cc)?t.cc=e.cc.length===1?e.cc[0].email:e.cc.map(r=>r.email):t.cc=e.cc.email),e.bcc&&(Array.isArray(e.bcc)?t.bcc=e.bcc.length===1?e.bcc[0].email:e.bcc.map(r=>r.email):t.bcc=e.bcc.email),e.replyTo&&(t.reply_to=[y(e.replyTo).address]),e.trackClicks!==void 0&&(t.track_clicks=e.trackClicks),e.trackOpens!==void 0&&(t.track_opens=e.trackOpens),e.clientReference&&(t.client_reference=e.clientReference),e.mimeHeaders&&Object.keys(e.mimeHeaders).length>0){const r={};for(const[a,f]of Object.entries(e.mimeHeaders))r[a]=f;t.mime_headers=r}if(e.headers){const r=v(e.headers);Object.keys(r).length>0&&(t.mime_headers??={},Object.entries(r).forEach(([a,f])=>{t.mime_headers&&(t.mime_headers[A(a)]=_(f))}))}e.attachments&&e.attachments.length>0&&(t.attachments=e.attachments.map(r=>{const a={name:r.filename};return r.content?(a.content=typeof r.content=="string"?r.content:r.content.toString("base64"),r.contentType&&(a.mime_type=r.contentType)):r.path&&(a.file_cache_key=r.path),a})),i.debug("Sending email via Zeptomail API",{subject:t.subject,to:t.to});const b={Accept:"application/json",Authorization:c.token,"Content-Type":"application/json"},n=await E(async()=>p(`${c.endpoint}/email`,{headers:b,method:"POST",timeout:c.timeout},JSON.stringify(t)),c.retries);if(!n.success){i.debug("API request failed",n.error);let r=n.error instanceof Error?n.error.message:"Unknown error";const a=n.data;return a?.body?.message?r+=` Details: ${a.body.message}`:a?.body?.error?.message&&(r+=` Details: ${a.body.error.message}`),{error:new l(s,`Failed to send email: ${r}`,{cause:n.error}),success:!1}}const m=n.data?.body,h=m?.request_id??k();return i.debug("Email sent successfully",{messageId:h}),{data:{messageId:h,provider:s,response:m,sent:!0,timestamp:new Date},success:!0}}catch(d){return{error:I(s,"send email",d,i),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{M as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/ahaSendProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/ahaSendProvider-D95-pwFh.js";export{r as ahaSendProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/awsSesProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/awsSesProvider-DnZo9X_g.js";export{a as awsSesProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/azureProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/azureProvider-D6Z4c1yT.js";export{a as azureProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/brevoProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/brevoProvider-D1yTSs0l.js";export{o as brevoProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/cloudflareEmailProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/cloudflareEmailProvider-DZbs35NL.js";export{e as cloudflareEmailProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/failoverProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/failoverProvider-IED1M0M5.js";export{o as failoverProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/httpProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/httpProvider-CpdWJoRq.js";export{e as httpProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/infobipProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/infobipProvider-DTqFu5pM.js";export{e as infobipProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/loopsProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/loopsProvider-PiE2HxoW.js";export{e as loopsProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/mailchannelsProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/mailchannelsProvider-Dn24mI8D.js";export{r as mailchannelsProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/mailCrabProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/mailCrabProvider-BSapw_mS.js";export{e as mailCrabProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/mailerSendProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/mailerSendProvider-B6X4Lhsf.js";export{a as mailerSendProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/mailgunProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/mailgunProvider-4sMtcQcW.js";export{e as mailgunProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/mailjetProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/mailjetProvider-DvrHwipw.js";export{a as mailjetProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/mailomatProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/mailomatProvider-CrkNQGfL.js";export{r as mailomatProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/mailPaceProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/mailPaceProvider-BugIutTw.js";export{r as mailPaceProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/mailtrapProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/mailtrapProvider-DTgvCUrs.js";export{e as mailtrapProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as d}from"../../packem_shared/mandrillProvider-
|
|
1
|
+
import{default as d}from"../../packem_shared/mandrillProvider-BaK0GEj7.js";export{d as mandrillProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/mockProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/mockProvider-CTxxbT0d.js";export{e as mockProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/netcoreProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/netcoreProvider-BZJ0noQ2.js";export{o as netcoreProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/nodemailerProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/nodemailerProvider-DqJh8ghN.js";export{o as nodemailerProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/outlook365Provider-
|
|
1
|
+
import{default as e}from"../../packem_shared/outlook365Provider-DQUSFy2d.js";export{e as outlook365Provider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/plunkProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/plunkProvider-WMi1yPya.js";export{o as plunkProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/postalProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/postalProvider-DpBFGpoX.js";export{a as postalProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/postmarkProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/postmarkProvider-ClUaHPvw.js";export{a as postmarkProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as d}from"../../packem_shared/resendProvider-
|
|
1
|
+
import{default as d}from"../../packem_shared/resendProvider-DtaB7sk0.js";export{d as resendProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/scalewayProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/scalewayProvider-BhbDUEah.js";export{r as scalewayProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as e}from"../../packem_shared/sendGridProvider-
|
|
1
|
+
import{default as e}from"../../packem_shared/sendGridProvider-DBZHhxd6.js";export{e as sendGridProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as o}from"../../packem_shared/smtpProvider-
|
|
1
|
+
import{default as o}from"../../packem_shared/smtpProvider-CjcOEiAh.js";export{o as smtpProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as a}from"../../packem_shared/sparkpostProvider-
|
|
1
|
+
import{default as a}from"../../packem_shared/sparkpostProvider-B19lU9D5.js";export{a as sparkpostProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/sweegoProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/sweegoProvider-H8KWGDff.js";export{r as sweegoProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{default as r}from"../../packem_shared/zeptomailProvider-
|
|
1
|
+
import{default as r}from"../../packem_shared/zeptomailProvider-L7nkdn0L.js";export{r as zeptomailProvider};
|
package/dist/test/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{emailMatchers as a,registerEmailMatchers as o,toHaveSentMatching as r,toHaveSentTo as i,toHaveSentWithAttachment as m,toHaveSentWithSubject as h}from"../packem_shared/emailMatchers-DpwItmkN.js";import{toEmailSnapshot as c}from"../packem_shared/toEmailSnapshot-BOhTn44E.js";import{createTestEmail as s}from"../packem_shared/createTestEmail-
|
|
1
|
+
import{emailMatchers as a,registerEmailMatchers as o,toHaveSentMatching as r,toHaveSentTo as i,toHaveSentWithAttachment as m,toHaveSentWithSubject as h}from"../packem_shared/emailMatchers-DpwItmkN.js";import{toEmailSnapshot as c}from"../packem_shared/toEmailSnapshot-BOhTn44E.js";import{createTestEmail as s}from"../packem_shared/createTestEmail-gr512snl.js";export{s as createTestEmail,a as emailMatchers,o as registerEmailMatchers,c as toEmailSnapshot,r as toHaveSentMatching,i as toHaveSentTo,m as toHaveSentWithAttachment,h as toHaveSentWithSubject};
|
package/package.json
CHANGED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import{createRequire as F}from"node:module";import M from"./EmailError-BIaHK1Uw.js";import X from"./RequiredOptionError-ctDEEB1s.js";import{c as J}from"./create-logger-CazqtXcL.js";import p from"../utils/format-email-address.js";import{h as Y}from"./headers-to-record-ZOZ7Dubo.js";import{m as Z}from"./make-request-Cyz5_yu8.js";import{a as _,s as O}from"./sanitize-header-CW0f3IT7.js";import{v as ee}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as re}from"./defineProvider-C9q-7iwt.js";let L;const Q=S=>(L??=F(import.meta.url))(S),b=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,G=S=>{if(typeof b<"u"&&b.versions&&b.versions.node){const[a,i]=b.versions.node.split(".").map(Number);if(a>22||a===22&&i>=3||a===20&&i>=16)return b.getBuiltinModule(S)}return Q(S)},{randomUUID:q,createHash:x,createHmac:w}=G("node:crypto"),te=globalThis.Buffer!==void 0,I=()=>{if(!te)throw new Error("Buffer is required for AWS SES provider");return globalThis.Buffer},y="aws-ses",j={apiVersion:"2010-12-01",maxAttempts:3,region:"us-east-1"},he=re((S={})=>{const a={...j,...S},i=J("AWS-SES",S.logger),k=(e,c,r,s,n)=>{const d=Object.keys(r).toSorted().map(u=>{const f=r[u];return f===void 0?"":`${encodeURIComponent(u)}=${encodeURIComponent(f)}`}).filter(Boolean).join("&"),t=`${Object.keys(s).toSorted().map(u=>`${u.toLowerCase()}:${s[u]}`).join(`
|
|
2
|
-
`)}
|
|
3
|
-
`,o=Object.keys(s).toSorted().map(u=>u.toLowerCase()).join(";"),g=x("sha256").update(n).digest("hex");return[e,c,d,t,o,g].join(`
|
|
4
|
-
`)},P=(e,c,r)=>{const s=e.slice(0,8),n=x("sha256").update(r).digest("hex");return["AWS4-HMAC-SHA256",e,`${s}/${c}/ses/aws4_request`,n].join(`
|
|
5
|
-
`)},B=(e,c,r,s)=>{const n=c.slice(0,8),d=w("sha256",`AWS4${e}`).update(n).digest(),t=w("sha256",d).update(r).digest(),o=w("sha256",t).update("ses").digest(),g=w("sha256",o).update("aws4_request").digest();return w("sha256",g).update(s).digest("hex")},W=(e,c,r,s,n)=>{const d=c.slice(0,8),t=Object.keys(s).toSorted().map(o=>o.toLowerCase()).join(";");return[`AWS4-HMAC-SHA256 Credential=${e}/${d}/${r}/ses/aws4_request`,`SignedHeaders=${t}`,`Signature=${n}`].join(", ")},R=async(e,c)=>{if(!a.accessKeyId||!a.secretAccessKey)throw i.debug("Missing required credentials: accessKeyId or secretAccessKey"),new X(y,["accessKeyId","secretAccessKey"]);try{const r=a.region||j.region,s=a.apiVersion||j.apiVersion,n=a.endpoint||`email.${r}.amazonaws.com`,d="/",t="POST";i.debug("Making request to AWS SES:",{action:e,host:n,region:r});const o=new URLSearchParams;o.append("Action",e),o.append("Version",s),Object.entries(c).forEach(([m,l])=>{l!=null&&o.append(m,String(l))});const g=o.toString();i.debug("Request body:",g);const f=new Date().toISOString().replaceAll(/[:-]|\.\d{3}/g,""),h={"Content-Length":I().byteLength(g).toString(),"Content-Type":"application/x-www-form-urlencoded",Host:n,"X-Amz-Date":f};a.sessionToken&&(h["X-Amz-Security-Token"]=a.sessionToken),i.debug("Request headers:",h);const D=k(t,d,{},h,g),z=P(f,r,D),U=B(a.secretAccessKey,f,r,z);h.Authorization=W(a.accessKeyId,f,r,h,U),i.debug("Making HTTPS request to:",`https://${n}${d}`);const N=`https://${n}${d}`,E=await Z(N,{headers:h,method:t},g);if(!E.success)throw E.error??new Error("AWS SES API request failed");const A=E.data?.body;if(!A)throw new Error("No response body from AWS SES");const v=E.data?.statusCode;i.debug("Response status:",v),i.debug("Response data:",A);const T=v;if(T&&T>=200&&T<300){const m={};if(e==="SendRawEmail"){const l=A.match(/<MessageId>(.*?)<\/MessageId>/);if(l){const[,V]=l;m.MessageId=V,i.debug("Extracted MessageId:",m.MessageId)}}else if(e==="GetSendQuota"){const l=A.match(/<Max24HourSend>(.*?)<\/Max24HourSend>/);l?.[1]&&(m.Max24HourSend=Number.parseFloat(l[1]),i.debug("Extracted Max24HourSend:",m.Max24HourSend))}return m}const C=A.match(/<Message>(.*?)<\/Message>/),H=C?C[1]:"Unknown AWS SES error";throw i.debug("AWS SES Error:",H),new Error(`AWS SES API Error: ${H}`)}catch(r){const s=r instanceof Error?r.message:String(r);throw i.debug("makeAwsRequest exception:",s),r instanceof Error?r:new Error(s)}},K=e=>{const c=`----=${q().replaceAll("-","")}`,r=new Date().toUTCString(),s=e.from.email.includes("@")?e.from.email.split("@")[1]:"localhost",n=`<${q().replaceAll("-","")}@${s}>`,d=I();let t="";if(t+=`From: ${p(e.from)}\r
|
|
6
|
-
`,t+=Array.isArray(e.to)?`To: ${e.to.map(o=>p(o)).join(", ")}\r
|
|
7
|
-
`:`To: ${p(e.to)}\r
|
|
8
|
-
`,e.cc&&(t+=Array.isArray(e.cc)?`Cc: ${e.cc.map(o=>p(o)).join(", ")}\r
|
|
9
|
-
`:`Cc: ${p(e.cc)}\r
|
|
10
|
-
`),e.bcc&&(t+=Array.isArray(e.bcc)?`Bcc: ${e.bcc.map(o=>p(o)).join(", ")}\r
|
|
11
|
-
`:`Bcc: ${p(e.bcc)}\r
|
|
12
|
-
`),t+=`Subject: ${_(e.subject)}\r
|
|
13
|
-
`,t+=`Date: ${r}\r
|
|
14
|
-
`,t+=`Message-ID: ${n}\r
|
|
15
|
-
`,t+=`MIME-Version: 1.0\r
|
|
16
|
-
`,e.headers){const o=Y(e.headers);for(const[g,u]of Object.entries(o)){const f=O(g),$=_(u);t+=`${f}: ${$}\r
|
|
17
|
-
`}}return t+=`Content-Type: multipart/alternative; boundary="${c}"\r
|
|
18
|
-
\r
|
|
19
|
-
`,e.text&&(t+=`--${c}\r
|
|
20
|
-
`,t+=`Content-Type: text/plain; charset=UTF-8\r
|
|
21
|
-
`,t+=`Content-Transfer-Encoding: base64\r
|
|
22
|
-
\r
|
|
23
|
-
`,t+=`${d.from(e.text,"utf8").toString("base64")}\r
|
|
24
|
-
\r
|
|
25
|
-
`),e.html&&(t+=`--${c}\r
|
|
26
|
-
`,t+=`Content-Type: text/html; charset=UTF-8\r
|
|
27
|
-
`,t+=`Content-Transfer-Encoding: base64\r
|
|
28
|
-
\r
|
|
29
|
-
`,t+=`${d.from(e.html,"utf8").toString("base64")}\r
|
|
30
|
-
\r
|
|
31
|
-
`),t+=`--${c}--\r
|
|
32
|
-
`,t};return{features:{attachments:!1,batchSending:!1,customHeaders:!0,html:!0,replyTo:!1,scheduling:!1,tagging:!1,templates:!1,tracking:!1},getInstance:()=>{},initialize(){i.debug("Initializing AWS SES provider with options:",{accessKeyId:a.accessKeyId?`***${a.accessKeyId.slice(-4)}`:void 0,endpoint:a.endpoint,region:a.region,secretAccessKey:a.secretAccessKey?"***":void 0})},async isAvailable(){try{return!!(await R("GetSendQuota",{})).Max24HourSend}catch{return!1}},name:y,options:a,async sendEmail(e){const c=r=>{const s=[];return r.attachments&&r.attachments.length>0&&s.push("attachments"),r.priority&&s.push("priority"),r.tags&&r.tags.length>0&&s.push("tags (use messageTags instead)"),r.replyTo&&s.push("replyTo"),s};try{const r=ee(e);if(r.length>0)throw new M(y,`Invalid email options: ${r.join(", ")}`);const s=c(e);if(s.length>0)throw new M(y,`Unsupported fields provided: ${s.join(", ")}. These fields are not supported by AWS SES Raw Email API and would be silently ignored.`);const n={};e.configurationSetName&&(n.ConfigurationSetName=e.configurationSetName),e.sourceArn&&(n.SourceArn=e.sourceArn),e.returnPath&&(n.ReturnPath=e.returnPath),e.returnPathArn&&(n.ReturnPathArn=e.returnPathArn),e.messageTags&&Object.keys(e.messageTags).length>0&&Object.entries(e.messageTags).forEach(([f,$],h)=>{n[`Tags.member.${h+1}.Name`]=f,n[`Tags.member.${h+1}.Value`]=$});const d=K(e),o=I().from(d).toString("base64");n["RawMessage.Data"]=o;const g=await R("SendRawEmail",n),u=g.MessageId;return!u||u.trim()===""?{error:new M(y,"AWS SES API returned a response without a MessageId. The email may not have been sent successfully."),success:!1}:{data:{messageId:u,provider:y,response:g,sent:!0,timestamp:new Date},success:!0}}catch(r){return{error:new M(y,`Failed to send email: ${r instanceof Error?r.message:String(r)}`,{cause:r instanceof Error?r:new Error(String(r))}),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{he as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createTransportDkimSigner as l}from"./DkimSigner-CCxFKitN.js";import o from"./EmailError-BIaHK1Uw.js";import m from"./RequiredOptionError-ctDEEB1s.js";import{b as u}from"./build-mime-message-BCFKPqaW.js";import{g as f}from"./generate-message-id-B2n2yqR6.js";import{h as g}from"./headers-to-record-ZOZ7Dubo.js";import{v as p}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as h}from"./defineProvider-C9q-7iwt.js";import{c as v,h as w}from"./provider-base-BEz00m9R.js";const r="cloudflare-email",R=h((s={})=>{if(typeof s.send!="function")throw new m(r,"send");const d=v(r,s.logger);return{features:{attachments:!0,batchSending:!1,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){await Promise.resolve()},async isAvailable(){return typeof s.send=="function"},name:r,async sendEmail(e){try{const a=p(e);if(a.length>0)return{error:new o(r,`Invalid email options: ${a.join(", ")}`),success:!1};const i=Array.isArray(e.to)?e.to:[e.to];if(i.length!==1||e.cc!==void 0||e.bcc!==void 0)return{error:new o(r,"Cloudflare Email supports exactly one `to` recipient and does not support cc/bcc"),success:!1};const[n]=i;if(!n)return{error:new o(r,"A single `to` recipient is required"),success:!1};const c=f();let t=await u({...e,headers:{...e.headers?g(e.headers):{},"Message-ID":c}});return s.dkim&&e.useDkim!==!1&&(t=await l(s.dkim).signMimeMessage(t)),await s.send(e.from.email,n.email,t),{data:{messageId:c,provider:r,sent:!0,timestamp:new Date},success:!0}}catch(a){return{error:w(r,"send email",a,d),success:!1}}},async validateCredentials(){return this.isAvailable()}}});export{R as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const o=()=>{const t="visulima.local",a=Date.now(),n=Math.random().toString(36).slice(2,10);return`<${a}.${n}@${t}>`};export{o as g};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import{createRequire as x}from"node:module";import{createTransportDkimSigner as W}from"./DkimSigner-CCxFKitN.js";import f from"./EmailError-BIaHK1Uw.js";import Y from"./RequiredOptionError-ctDEEB1s.js";import{b as Q}from"./build-mime-message-BCFKPqaW.js";import{g as K}from"./generate-message-id-B2n2yqR6.js";import{v as O}from"./validate-email-options-DxdAVLlu.js";import{defineProvider as J}from"./defineProvider-C9q-7iwt.js";let q;const G=d=>(q??=x(import.meta.url))(d),I=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,R=d=>{if(typeof I<"u"&&I.versions&&I.versions.node){const[t,T]=I.versions.node.split(".").map(Number);if(t>22||t===22&&T>=3||t===20&&T>=16)return I.getBuiltinModule(d)}return G(d)},{Buffer:S}=R("node:buffer"),{createHmac:B}=R("node:crypto"),{Socket:X,createConnection:V}=R("node:net"),{connect:H}=R("node:tls"),Z=(d,t)=>new Promise(T=>{const w=new X,y=()=>{w.destroy(),T(!1)};w.setTimeout(1e3),w.on("error",y),w.on("timeout",y),w.connect(t,d,()=>{w.end(),T(!0)})}),l="smtp",ee=25,te=465,re=1e4,se=!1,oe=5,N=3e4,ne=/^\./,pe=J((d={})=>{if(!d.host)throw new Y(l,"host");const t={authMethod:d.authMethod??"LOGIN",debug:d.debug??!1,dkim:d.dkim,host:d.host,maxConnections:d.maxConnections??oe,oauth2:d.oauth2,password:d.password,pool:d.pool??!1,port:d.port!==void 0?d.port:d.secure?te:ee,rejectUnauthorized:d.rejectUnauthorized??!0,retries:d.retries??0,secure:d.secure??se,timeout:d.timeout??re,user:d.user,...d.logger&&{logger:d.logger}};let T=!1;const w=[],y=[];let M=0;const j=()=>{M+=1},U=()=>{M>0&&(M-=1)},b=e=>e.replaceAll(/[\r\n\t\v\f]/g," ").trim(),L=e=>{const a=e.split(`\r
|
|
2
|
-
`),o={};for(const i of a)if(i.startsWith("250-")||i.startsWith("250 ")){const c=i.slice(4).trim().split(" "),s=c[0];s&&(o[s]=c.slice(1))}return o},p=async(e,a,o)=>new Promise((i,u)=>{const c=Array.isArray(o)?o:[o];let s="",n="";const h=setTimeout(()=>{g(),u(new f(l,`Command timeout after ${t.timeout}ms: ${a?.slice(0,50)}...`))},t.timeout),g=()=>{e.removeListener("data",$),e.removeListener("error",r),h&&clearTimeout(h)},$=m=>{s+=m.toString();const E=s.split(`\r
|
|
3
|
-
`).filter(Boolean);if(E.length>0){const C=E.at(-1);if(C){const _=C.match(/^(\d{3})[\s-]/);if(_){const[,z]=_;n=z,C[3]===" "&&(g(),c.includes(n)?i(s):u(new f(l,`Expected ${c.join(" or ")}, got ${n}: ${s.trim()}`)))}}}},r=m=>{g(),u(new f(l,`Socket error: ${m.message}`,{cause:m}))};e.on("data",$),e.on("error",r),a&&e.write(`${a}\r
|
|
4
|
-
`)}),v=async()=>{if(t.pool&&w.length>0){const e=w.pop();if(e&&!e.destroyed)return e;e&&U()}return t.pool&&M>=t.maxConnections?new Promise((e,a)=>{const o={reject:a,resolve:e};o.timeout=setTimeout(()=>{const i=y.indexOf(o);i!==-1&&y.splice(i,1),a(new f(l,`Connection queue timeout after ${N}ms`))},N),y.push(o)}):new Promise((e,a)=>{let o,i=!1,u;const c=()=>{o&&clearTimeout(o)};o=setTimeout(()=>{i||(i=!0,u&&!u.destroyed&&u.destroy(),c(),a(new f(l,`Connection timeout to ${t.host}:${t.port} after ${t.timeout}ms`)))},t.timeout);try{u=t.secure?H({host:t.host,port:t.port,rejectUnauthorized:t.rejectUnauthorized}):V(t.port,t.host),u.on("error",s=>{i||(i=!0,c(),a(new f(l,`Connection error: ${s.message}`,{cause:s})))}),u.once("data",s=>{if(!i&&u){i=!0,c();const n=s.toString();n.slice(0,3)==="220"?(j(),e(u)):(u.destroy(),a(new f(l,`Unexpected server greeting: ${n.trim()}`)))}})}catch(s){i||(i=!0,c(),a(new f(l,`Failed to create connection: ${s.message}`,{cause:s})))}})},P=async e=>new Promise((a,o)=>{let i,u=!1,c;const s=()=>{i&&clearTimeout(i)};i=setTimeout(()=>{u||(u=!0,c&&!c.destroyed&&c.destroy(),s(),o(new f(l,`TLS connection timeout after ${t.timeout}ms`)))},t.timeout);try{const n={host:t.host,rejectUnauthorized:t.rejectUnauthorized,socket:e};c=H(n),c.on("error",h=>{u||(u=!0,s(),o(new f(l,`TLS connection error: ${h.message}`,{cause:h})))}),c.once("secure",()=>{!u&&c&&(u=!0,s(),a(c))})}catch(n){u||(u=!0,s(),o(new f(l,`Failed to upgrade to TLS: ${n.message}`,{cause:n})))}}),k=e=>{if(e.destroyed||!t.pool){try{e.destroy()}catch{}U();return}if(y.length>0){const a=y.shift();if(a){clearTimeout(a.timeout),a.resolve(e);return}}w.push(e)},A=async(e,a=!1)=>{if(a){if(!e.destroyed)try{await p(e,"RSET","250")}catch{e.destroy()}k(e);return}await new Promise(o=>{try{U(),e.write(`QUIT\r
|
|
5
|
-
`),e.end(),e.once("close",()=>{o()})}catch{o()}})},D=async e=>{if(!t.user)return;const a=await p(e,`EHLO ${t.host}`,"250"),o=L(a),i=Object.keys(o).find(s=>s.toUpperCase()==="AUTH");if(!i&&(t.user||t.password))throw new f(l,"Server does not support authentication");const u=i?o[i]??[]:[];let{authMethod:c}=t;if(c||(u.includes("CRAM-MD5")?c="CRAM-MD5":u.includes("LOGIN")?c="LOGIN":u.includes("PLAIN")&&(c="PLAIN")),!c)throw new f(l,"No supported authentication methods");if(c==="OAUTH2"&&t.oauth2)try{const{accessToken:s,user:n}=t.oauth2,h=`user=${n}auth=Bearer ${s}`,g=S.from(h).toString("base64");await p(e,`AUTH XOAUTH2 ${g}`,"235");return}catch(s){const n=s.message;throw n.includes("535")||n.includes("Authentication failed")?new f(l,"Authentication failed: Invalid OAuth2 credentials"):s}if(c==="CRAM-MD5"&&t.password)try{const n=(await p(e,"AUTH CRAM-MD5","334")).split(" ")[1];if(!n)throw new f(l,"Invalid CRAM-MD5 challenge response");const h=S.from(n,"base64").toString("utf8"),g=B("md5",t.password);g.update(h);const $=g.digest("hex"),r=`${t.user} ${$}`;await p(e,S.from(r).toString("base64"),"235");return}catch(s){const n=s.message;throw n.includes("535")||n.includes("Authentication failed")?new f(l,"Authentication failed: Invalid username or password"):s}if(c==="LOGIN"&&t.password)try{await p(e,"AUTH LOGIN","334"),await p(e,S.from(t.user).toString("base64"),"334"),await p(e,S.from(t.password).toString("base64"),"235");return}catch(s){const n=s.message;throw n.includes("535")||n.includes("Authentication failed")?new f(l,"Authentication failed: Invalid username or password"):s}if(c==="PLAIN"&&t.password)try{const s=S.from(`\0${t.user}\0${t.password}`).toString("base64");await p(e,`AUTH PLAIN ${s}`,"235");return}catch(s){const n=s.message;throw n.includes("535")||n.includes("Authentication failed")?new f(l,"Authentication failed: Invalid username or password"):s}throw new f(l,"Authentication failed - no valid credentials or method")},F=async e=>{if(!t.dkim)return e;try{return await W(t.dkim).signMimeMessage(e)}catch(a){throw new f(l,`DKIM signing failed: ${a.message}`)}};return{features:{attachments:!0,batchSending:t.pool,customHeaders:!0,html:!0,replyTo:!0,scheduling:!1,tagging:!1,templates:!1,tracking:!1},async initialize(){if(!T)try{if(!await this.isAvailable())throw new f(l,`SMTP server not available at ${t.host}:${t.port}`);T=!0}catch(e){throw new f(l,`Failed to initialize: ${e.message}`,{cause:e})}},async isAvailable(){try{if(!await Z(t.host,t.port))return!1;const a=await v();return await A(a),!0}catch{return!1}},name:l,options:t,async sendEmail(e){try{const a=O(e);if(a.length>0)return{error:new f(l,`Invalid email options: ${a.join(", ")}`),success:!1};T||await this.initialize();let o=await v();try{let i=L(await p(o,`EHLO ${t.host}`,"250"));if(!t.secure)try{const r=await p(o,`EHLO ${t.host}`,"250"),m=L(r);i=m,Object.keys(m).includes("STARTTLS")&&(await p(o,"STARTTLS","220"),o=await P(o),i=L(await p(o,`EHLO ${t.host}`,"250")))}catch(r){if(t.rejectUnauthorized)throw new f(l,`STARTTLS failed or not supported: ${r.message}`,{cause:r})}await D(o);const u=Object.keys(i).some(r=>r.toUpperCase()==="DSN");let c="";if(e.dsn&&u){const r=[];e.dsn.success&&r.push("SUCCESS"),e.dsn.failure&&r.push("FAILURE"),e.dsn.delay&&r.push("DELAY"),r.length>0&&(c=` NOTIFY=${r.join(",")}`)}await p(o,`MAIL FROM:<${e.from.email}>`,"250");const s=[];Array.isArray(e.to)?s.push(...e.to.map(r=>r.email)):s.push(e.to.email),e.cc&&(Array.isArray(e.cc)?s.push(...e.cc.map(r=>r.email)):s.push(e.cc.email)),e.bcc&&(Array.isArray(e.bcc)?s.push(...e.bcc.map(r=>r.email)):s.push(e.bcc.email));for(const r of s)await p(o,`RCPT TO:<${r}>${c}`,"250");await p(o,"DATA","354");let n=await Q(e);const h=[];if(e.dsn&&!u){const r=[];e.dsn.success&&r.push("SUCCESS"),e.dsn.failure&&r.push("FAILURE"),e.dsn.delay&&r.push("DELAY"),r.length>0&&h.push(`X-DSN-NOTIFY: ${r.join(",")}`)}if(e.priority){let r="";switch(e.priority){case"high":{r="1 (Highest)",h.push("Importance: High");break}case"low":{r="5 (Lowest)",h.push("Importance: Low");break}case"normal":{r="3 (Normal)",h.push("Importance: Normal");break}default:{r="3 (Normal)";break}}h.push(`X-Priority: ${r}`)}if(e.inReplyTo&&h.push(`In-Reply-To: ${b(e.inReplyTo)}`),e.references){const r=Array.isArray(e.references)?e.references.map(m=>b(m)).join(" "):b(e.references);h.push(`References: ${r}`)}if(e.listUnsubscribe){const r=Array.isArray(e.listUnsubscribe)?e.listUnsubscribe.map(m=>`<${b(m)}>`).join(", "):`<${b(e.listUnsubscribe)}>`;h.push(`List-Unsubscribe: ${r}`)}if(e.googleMailHeaders){const{googleMailHeaders:r}=e;r.feedbackId&&h.push(`Feedback-ID: ${b(r.feedbackId)}`),r.promotionalContent&&h.push("X-Google-Promotion: promotional"),r.category&&h.push(`X-Gmail-Labels: ${r.category}`)}if(h.length>0){const r=n.indexOf(`\r
|
|
6
|
-
\r
|
|
7
|
-
`);if(r!==-1){const m=n.slice(0,r),E=n.slice(r+4);n=`${m}\r
|
|
8
|
-
${h.join(`\r
|
|
9
|
-
`)}\r
|
|
10
|
-
\r
|
|
11
|
-
${E}`}}t.dkim&&(e.useDkim||e.useDkim===void 0)&&(n=await F(n));const g=n.replaceAll(`\r
|
|
12
|
-
.`,`\r
|
|
13
|
-
..`).replace(ne,"..");await p(o,`${g}\r
|
|
14
|
-
.`,"250");const $=K();return await A(o,t.pool),{data:{messageId:$,provider:l,response:"Message accepted",sent:!0,timestamp:new Date},success:!0}}catch(i){try{await A(o)}catch{}throw i}}catch(a){return{error:new f(l,`Failed to send email: ${a.message}`,{cause:a}),success:!1}}},async shutdown(){for(const e of w)try{await A(e)}catch{}w.length=0;for(const e of y)clearTimeout(e.timeout),e.reject(new Error("Provider shutdown"));y.length=0},async validateCredentials(){try{if(!await this.isAvailable())return!1;let e=await v();try{if(await p(e,`EHLO ${t.host}`,"250"),!t.secure)try{const a=await p(e,`EHLO ${t.host}`,"250"),o=L(a);Object.keys(o).includes("STARTTLS")&&(await p(e,"STARTTLS","220"),e=await P(e),await p(e,`EHLO ${t.host}`,"250"))}catch{if(t.rejectUnauthorized)return await A(e),!1}return await D(e),await A(e),!0}catch{return await A(e),!1}}catch{return!1}}}});export{pe as default};
|