Angular 7 + .Net core 2 send report as email attachment
Angular 7 + .Net core 2 send report as email attachment
Hi
Using Angular 7 + .Net core 2 it is possible to send a report as email attachment?
I found a sample https://github.com/stimulsoft/Samples-N ... by%20Email of you but it is for only .NET Core MVC
thanks
Using Angular 7 + .Net core 2 it is possible to send a report as email attachment?
I found a sample https://github.com/stimulsoft/Samples-N ... by%20Email of you but it is for only .NET Core MVC
thanks
Re: Angular 7 + .Net core 2 send report as email attachment
Hello.
You could export the report from .Net Core or Angular.
In the first case, the .Net Core engine will be used.
In the second case, the JavaScript engine will be used.
We have one sample for your compination of the technologies only.
https://github.com/stimulsoft/Samples-N ... %20Angular
Thank you.
You could export the report from .Net Core or Angular.
In the first case, the .Net Core engine will be used.
In the second case, the JavaScript engine will be used.
We have one sample for your compination of the technologies only.
https://github.com/stimulsoft/Samples-N ... %20Angular
Thank you.
Re: Angular 7 + .Net core 2 send report as email attachment
Hi
I've started from this sample https://github.com/stimulsoft/Samples-J ... by%20Email
and seems to work,just couple things:
how can I set default values from code for fields in email options window:
thnks
I've started from this sample https://github.com/stimulsoft/Samples-J ... by%20Email
and seems to work,just couple things:
how can I set default values from code for fields in email options window:
thnks
Re: Angular 7 + .Net core 2 send report as email attachment
I'found in manual:
thanks
Code: Select all
options.email.defaultEmailAddress = "recipient_address@gmail.com";
options.email.defaultEmailSubject = "New Invoice";
options.email.defaultEmailMessage = "Please check the new invoice in the attachment";
Re: Angular 7 + .Net core 2 send report as email attachment
that's our final code in case someone needs it:
js:
C#:
js:
Code: Select all
this.options.toolbar.showSendEmailButton = true;
this.viewer.onEmailReport = function (args) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState === 4) { // this.status
if (this.responseText === 'OK') {
alert("Message sent!");
}
else {
alert(this.responseText);
}
}
};
xhr.open('POST', '/api/sendmail', true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
fileName: args.fileName,
format: args.format,
data: Stimulsoft.System.Convert.toBase64String(args.data),
email: args.settings.email,
subject: args.settings.subject,
message: args.settings.message
}));
};
}
C#:
Code: Select all
public class clientMailData
{
public string fileName { get; set; }
public string format { get; set; }
public string data { get; set; }
public string email { get; set; }
public string subject { get; set; }
public string message { get; set; }
}
public class stiEmailOptions
{
public stiEmailOptions()
{
AddressFrom = string.Empty;
AddressTo = string.Empty;
Host = "localhost";
Body = string.Empty;
Subject = string.Empty;
Port = 25;
BCC = new ArrayList();
CC = new ArrayList();
}
public string AddressFrom { get; set; }
public string AddressTo { get; set; }
public string Subject { get; set; }
public string Body { get; set; }
public string Host { get; set; }
public int Port { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public bool EnableSsl { get; set; }
public ArrayList CC { get; set; }
public ArrayList BCC { get; set; }
}
public class emailController : Controller
{
[Route("/api/sendmail")]
[HttpPost]
public IActionResult sendEmail([FromBody] clientMailData cld)
{
var data = cld.data;
var stream = new MemoryStream(Convert.FromBase64String(data));
var attachmentName = cld.fileName;
var format = cld.format;
switch (format)
{
case "Pdf":
attachmentName += ".pdf";
break;
case "Html":
case "Html5":
attachmentName += ".html";
break;
case "Word2007":
attachmentName += ".docx";
break;
case "Excel2007":
attachmentName += ".xlsx";
break;
case "Csv":
attachmentName += ".csv";
break;
}
var options = new stiEmailOptions
{ AddressTo = cld.email,
Subject = cld.subject,
Body = cld.message,
AddressFrom = ".....",
Host = ".....", //smtp
Port = 25,
UserName = ".....",
EnableSsl = true,
Password = "....."
};
return Ok(sendReportEmail(stream, attachmentName, options));
}
public static string sendReportEmail(Stream stream, string attachmentName, stiEmailOptions options)
{
var result = "OK";
try
{
stream.Seek(0, SeekOrigin.Begin);
var attachment = new Attachment(stream, attachmentName);
var message = new MailMessage(options.AddressFrom, options.AddressTo);
message.Attachments.Add(attachment);
message.Subject = options.Subject;
foreach (object email in options.CC)
{
if (email is MailAddress)
message.CC.Add((MailAddress)email);
else
message.CC.Add((string)email);
}
foreach (object email in options.BCC)
{
if (email is MailAddress)
message.Bcc.Add((MailAddress)email);
else
message.Bcc.Add((string)email);
}
if (string.IsNullOrEmpty(options.Body))
message.Body = string.Format("This Email contains the '{0}' report file.", attachmentName);
else
message.Body = options.Body;
SmtpClient client = new SmtpClient(options.Host, options.Port);
client.EnableSsl = options.EnableSsl;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(options.UserName, options.Password);
client.Send(message);
}
catch (Exception e)
{
result = e.InnerException != null ? e.InnerException.Message : e.Message;
}
return result;
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
}
base.Dispose(disposing);
}
}
Re: Angular 7 + .Net core 2 send report as email attachment
Hello,
Thank you for sharing your code!
Thank you for sharing your code!
Re: Angular 7 + .Net core 2 send report as email attachment
you're welcome
-
- Posts: 6254
- Joined: Tue Mar 20, 2018 5:34 am
Re: Angular 7 + .Net core 2 send report as email attachment
Hello
Thank you.
Please let us know if you need any additional help.
Thank you.
Please let us know if you need any additional help.