Exemplo n.º 1
0
        private async Task <bool> SendMailAsync(string subject, string body, string emailAddressRecipient, Stream attachment, string attachmentType)
        {
            if (!USE_TESTMODE)
            {
                var mailCredentials = MailCredentialsHelper.GetMailCredentials();
                try
                {
                    MailMessage msg = new MailMessage();
                    string[]    str = new string[] { emailAddressRecipient };
                    msg.IsBodyHtml = true;
                    //Empfänger hinzufügen
                    foreach (string empf in str)
                    {
                        msg.To.Add(new MailAddress(empf));
                    }
                    msg.From    = mailCredentials.MailAddress;
                    msg.Subject = subject;
                    msg.Body    = body;

                    if (attachment != null)
                    {
                        msg.Attachments.Add(new Attachment(attachment, attachmentType));
                    }

                    SmtpClient client = new SmtpClient();
                    client.UseDefaultCredentials = false;

                    client.Credentials = mailCredentials.NetworkCredential;

                    client.Port = mailCredentials.Port;

                    client.Host           = mailCredentials.Host;
                    client.DeliveryMethod = SmtpDeliveryMethod.Network;
                    client.EnableSsl      = true;
                    await client.SendMailAsync(msg);

                    return(true);
                }
                catch (Exception ex)
                {
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.Message);
                    return(false);
                }
            }
            else
            {
                return(CreateMailFiles(body, emailAddressRecipient, attachment, attachmentType));
            }
        }
Exemplo n.º 2
0
 public async Task <IActionResult> GetEmailCredentials()
 {
     return(await Task.FromResult(Ok(_mapper.Map <MailCredentialsSerializableDto>(new MailCredentialsSerializable(MailCredentialsHelper.GetMailCredentials())))));
 }