public ResponseRequestDTO <GeneratePasswordUserViewDTO> sendMail(GeneratePasswordUserViewDTO model) { var response = new ResponseRequestDTO <GeneratePasswordUserViewDTO> { code = STATE_MAIL_OK, dateResponse = DateTime.UtcNow, modelResponse = model, message = "Credenciales Enviadas correctamente al usuario" }; var mailResponse = new MessageMail() .addFrom(EMAIL_EMISOR) .addToList(model.email) .addSubject(SUBJECT_GENERATE_PASSWORD) .addBodyMessage(formatMessageForGenerateCredentialsUser(model)) .enableBodyHtml() .send(); if (!mailResponse) { response.code = 400; // bad request response.message = "Error al enviar el correo con las credenciales de usuario"; } return(response); }
public static string formatMessageForGenerateCredentialsUser(GeneratePasswordUserViewDTO model) { StringBuilder sb = new StringBuilder(); string textTitle = "Bienvenido a la Plataforma Tecnológica de la Industria del Transporte mas grande de toda Bolívia : Portal Clientes Delta Cargo SRL"; string textDescription = "Hemos recibido tu solicitud de afiliarte como cliente de la empresa, a continuación te mandamos tus <strong>credenciales de usuario</strong> por defecto, posteriomente podras cambiar tu contraseña"; return(sb.AppendLine("<html>") .AppendLine("<body>") .AppendLine($"<strong>{textTitle}</strong>") .AppendLine("</br>") .AppendLine(textDescription) .AppendLine("</br></br>") .AppendLine("<table border=\"1\">") .AppendLine(dataBody(model)) .AppendLine("</table>") .AppendLine("</body>") .AppendLine("</html>") .ToString()); }
public static string dataBody(GeneratePasswordUserViewDTO model) { StringBuilder st = new StringBuilder(); Dictionary <string, object> headerText = new Dictionary <string, object>() { ["Correo Electrónico"] = model.email, ["Contraseña"] = model.password, ["URL Portal Clientes"] = model.url }; foreach (var item in headerText) { st.AppendLine("<tr>") .AppendLine($"<td><strong>{item.Key}</strong></td>") .AppendLine($"<td><i>{item.Value}</i></td>") .AppendLine("</tr>"); } return(st.ToString()); }
public UserDTO generateFirstPassword(int userId) { var userFind = getById(userId); if (!isNull(userFind) && userFind.enviar_password == 1) { userFind.password = RandomPassword.randomPassword(acceptToUpper: true); // enviar password userFind.enviar_password = 0; // inhabilitar envio de password var generatePassUserView = new GeneratePasswordUserViewDTO { email = userFind.correo, password = userFind.password, url = URL_PORTAL_CLIENTES }; var response = mailServiceDAL.sendMail(generatePassUserView); if (response.code == STATE_MAIL_OK) { return((UserDTO)edit(userFind)); } } return((UserDTO)userFind); }