Last active
January 14, 2024 17:32
-
-
Save jonathasborges1/808f7600fd724d96ca4047ca56ab9fa1 to your computer and use it in GitHub Desktop.
Envio Automatico de resposta ao formulario v0.0.2 beta usando app script do google
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testeEnviarEmail() { | |
var e = { | |
namedValues: { | |
"email": ["[email protected]"], | |
"assunto": ["Testando conteudo do assunto"], | |
"mensagem": ["testando o Corpo da mensagem"] | |
} | |
}; | |
enviarEmailDeConfirmacao(e); | |
} | |
function enviarEmailDeConfirmacao(e) { | |
var respostas = e.namedValues; | |
console.log("respostas: ",respostas); | |
let email = undefined; | |
for (Key in respostas) { | |
if ( Key.toLowerCase() === 'endereço de e-mail' || Key.toLowerCase() === 'email') { | |
email = respostas[Key][0]; | |
break; // Interrompe o loop assim que encontrar o email | |
} | |
} | |
if(email){ | |
var assunto = "Confirmação de Recebimento - Pagina de Contato - Google Forms"; | |
var mensagem = createMimeMessage(email); | |
var emailCC = "Suporte em TI <[email protected]>"; | |
GmailApp.sendEmail(email, assunto, mensagem, { cc: emailCC, htmlBody: mensagem }); | |
console.log("Email de confirmacao Enviado com Sucesso."); | |
}else{ | |
console.log("O objeto de evento ou seus valores estão indefinidos."); | |
} | |
} | |
const createMimeMessage = (email) => { | |
const currentTime = new Date().toLocaleString('pt-BR', { | |
timeZone: 'America/Manaus', | |
day: '2-digit', | |
month: '2-digit', | |
year: 'numeric', | |
hour: '2-digit', | |
minute: '2-digit' | |
}).replace(',',' às'); | |
const bodyEmail = ` | |
<html> | |
<body> | |
Obrigado ${email} por preencher o formulário da nossa pagina de contato. Sua resposta foi recebida com sucesso e em breve retornaremos sua mensagem. | |
<br><br> | |
<i>Horário de Manaus em ${currentTime}</i><br> | |
<span style="color: grey;">Esta mensagem foi gerada automaticamente através do serviço Google Apps Script - script.google.com, por favor não responda esta mensagem.</span> | |
</body> | |
</html> | |
`; | |
return bodyEmail; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment