0
Good afternoon guys, I have a modal, where the user can send an email, in this modal, I loaded a HTML
, so that I can generate the PDF and attach to send in the email.
But I’ve seen several articles on the Internet, and I’m even a little confused, in which line of reasoning should I follow.
Follow in the API how the email is sent:
[HttpPut]
[Route("sendEmail")]
[Authorize(AuthenticationSchemes = "Bearer", Policy = WriteBudgetPolicy.Name)]
public async Task<IActionResult> SendEmail(EmailProposalsViewModel obj)
{
var company = _companyAppService.GetUnique(obj.CompanyId);
var result = new ReturnViewModel { Model = company };
try
{
await Util.SendEmailProposalsAsync(obj.Email, company.Email, company.Password, company.Port.Value, company.Server, obj.Message, obj.Subject, company.Name);
}
catch (Exception ex)
{
result.Errors = new Error { Key = "SendEmail", Value = ex.Message };
}
return ApplicationResult(result);
}
public static Task SendEmailProposalsAsync(string destinatario, string remetente, string password, int port, string host, string message, string subject, string displayName)
{
var msg = new MailMessage
{
From = new MailAddress(remetente, displayName),
To = { destinatario },
Subject = subject,
Body = message,
IsBodyHtml = true,
};
var smtpCliente = new SmtpClient(host, port);
smtpCliente.UseDefaultCredentials = false;
var credentials = new NetworkCredential(remetente, password);
smtpCliente.Credentials = credentials;
smtpCliente.EnableSsl = false;
if (host == "gmail.com")
{
smtpCliente.Host = "smtp.gmail.com";
smtpCliente.EnableSsl = true;
}
if (host == "yahoo.com.br")
{
smtpCliente.Host = "smtp.mail.yahoo.br";
}
if (host == "hotmail.com")
{
smtpCliente.Host = "smtp.live.com";
smtpCliente.EnableSsl = true;
}
if (host == "live.com")
{
smtpCliente.Host = "smtp.live.com";
smtpCliente.EnableSsl = true;
}
smtpCliente.Send(msg);
return Task.FromResult(0);
}
The front-end
is in angular, it would be possible to generate the PDF and send by email, without needing to save(that would be ideal)?
Utilizdo .net core
You can generate it in the front end and post to the backend and send, generate and send in the backend, have a template and change the values before sending... There are several different approaches and depend a lot on your scenario and need.
– Leandro Angelo
@Leandroangelo my need, would take advantage of the front, because I already have a whole HTML ready, just wanted to generate it in PDF in case, if it was possible to only save temporarily, and then send as an attachment in the email.
– Mariana