ctrlmailenable
v1.0.2
Published
CtrlMailEnable é um conjunto de funções para gerenciar o MailEnable
Downloads
9
Maintainers
Readme
CtrlMailEnable
CtrlMailEnable é um conjunto de funções para gerenciar o MailEnable
MailEnable é um servidor de e-mail, porem, não possui API. Toda gestão é feita via interface gráfica ou via powershell, o que acaba dificultando um gerenciamento automático do servidor. Para contornar isto, criei um repositório que gerencia as contas utilizando o PowerShell.
Instalando
npm install ctrlmailenable
Carregando o repositório
var MailEnableCtrl = require('CtrlMailEnable');
Iniciando
Antes de executar alguma das funções precisamos definir iniciar o Powershell e carregar os comandos do MailEnable. Esta é uma função assíncrona e após sua conclusão é feito as chamadas as funções.
MailEnableCtrl.init().then(function(){
// Aqui você faz a chamada a função desejada
}).catch(function(err){
console.log(err);
});
Listar as Contas
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.contas_listar().then(function(DadRet){
console.log(JSON.stringify(DadRet));
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Retorno
{
"cmacetko_teste1.com.br": {
"Conta": "cmacetko_teste1.com.br",
"Status": "1"
}
}
Verifica se uma Conta Existe
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.contas_is("example.com").then(function(DadRet){
console.log(JSON.stringify(DadRet));
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Retorno
true/false
Altera o Status de uma Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.contas_status("example.com", true).then(function(){
console.log("Sucesso");
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Criar uma Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.contas_criar("examplec.com").then(function(){
console.log("Sucesso");
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Deletar Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.contas_deletar("examplec.com").then(function(){
console.log("Sucesso");
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Listar E-mails de uma Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.emails_listar("examplec.com").then(function(DadRet){
console.log(JSON.stringify(DadRet));
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Retorno
[
{
"Nome":"Postmaster",
"Status":"1",
"Limite":"-1",
"Tamanho":"0"
},
{
"Nome":"teste1",
"Status":"1",
"Limite":"-1",
"Tamanho":"0"
}
]
Verificar se um E-mail Existe em uma Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.emails_is("examplec.com", "teste1").then(function(DadRet){
console.log(JSON.stringify(DadRet));
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Retorno
true/false
Cria um E-mail em uma Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.emails_criar("examplec.com", "teste1", "123456", "250000").then(function(){
console.log("Sucesso");
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Alterar Senha de um E-mail de uma Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.emails_alterar_senha("examplec.com", "teste1", "123456").then(function(){
console.log("Sucesso");
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Alterar Limite de um E-mail de uma Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.emails_alterar_limite("examplec.com", "teste1", "250000").then(function(){
console.log("Sucesso");
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Alterar Status de um E-mail de uma Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.emails_alterar_status("examplec.com", "teste1", true).then(function(){
console.log("Sucesso");
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Deletar E-mail de uma Conta
Chamando
MailEnableCtrl.init().then(function(){
MailEnableCtrl.emails_deletar("examplec.com", "teste1").then(function(){
console.log("Sucesso");
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Referências
Sucesso/Erro
Em todas funções temos o retorno controlado em then e catch (Padrão para funções Promises). Na função catch esta presente um parâmetro que retorna um objeto Error indiando a causa do erro.
Exemplo de Erro
Chamada
MailEnableCtrl.init().then(function(){
MailEnableCtrl.emails_deletar("XXXXXXXXXXX").then(function(){
console.log("OK");
}).catch(function(err){
console.log(err);
});
}).catch(function(err){
console.log(err);
});
Retorno
Error: Error: Error: Conta nao localizada
at Promise (C:\index.js:535:19)
at new Promise (<anonymous>)
at Object.contas_criar (G:\index.js:362:12)
at G:\tests.js:7:19
Contato
Paloma Macetko
- [email protected]
- https://github.com/cmacetko/
- https://www.npmjs.com/~cmacetko
- https://cmacetko.medium.com
- https://www.facebook.com/cmacetko
- https://www.instagram.com/cmacetko/
- https://twitter.com/cmacetko
- Skype: cmacetko
- Whatsapp: 47-91277858