I created a Subform that basically asks a Yes or No question (i.e. do you want to send an email), if the user clicks Yes I need to send it. I know that I can have my customization trigger a transaction that will then trigger a BPM to send the email, but my question is: can’t I just put the “send email” code in the Customization Script instead? Has anyone done something like this? I’m struggling to identify the assemblies I need.
You’ll need to add a reference to ICE (I think it’s Ice.Core? That or Ice.Framework), but then you should be able to just go:
using Ice.Core;
using Ice.Lib.Framework;
using Ice.Lib.Customization;
var mailer = this.GetMailer(async:true);
var message = new Ice.Mail.SmtpMail();
message.SetFrom("example@example.com");
message.SetTo("example@example.com");
message.SetCC("example@example.com");
message.SetSubject("Subject");
message.SetBody("Email Body Text");
message.IsBodyHtml = true;
mailer.Send(message);
That will allow also you to add HTML formatting so your alerts look more professional.
For some reason you dont have your epicor mailer set up, you can do the old fashioned way:
NetworkCredential basicCredential =
new NetworkCredential("uremail@domain.com", urpassword);
MailAddress fromAddress = new MailAddress("WhoIsSender@domain.com");
smtpClient.Host = "mail.yourSMTP.com";
smtpClient.Port = 25;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
smtpClient.EnableSsl = true;
MailMessage message = new MailMessage();
//-------> THIS IS WHAT YOU WANT! ---->message.Attachments.Add(new Attachment(PathToAttachment));
message.From = fromAddress;
message.Subject = "Testing customiztion from E10";
//Set IsBodyHtml to true means you can send HTML email.
message.IsBodyHtml = true;
message.Body = "<h1>This was created from within EPICOR..</h1><BR>On the receipt entry screen";
message.To.Add("receipient1@domain.com");
try
{
smtpClient.Send(message);
}
catch(Exception ex)
{
//Error, could not send the message
// Response.Write(ex.Message);
MessageBox.Show(ex.Message);
}
I mixed up your question with another. The other solutions are cleaner. The only time you’d want to use the Outlook version is if you want to track the email in your Sent folder.
SmtpClient client = new SmtpClient("smtp.office365.com");
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("YourSendingEmailAddress@domain.com", "yourPassword", "domain.com");//this is the account you'll send from
client.Port = 587;
client.EnableSsl = true;
MailAddress from = new MailAddress("fromemail@domain.com");//If you enable send-as on the sending account, you can make the "from" dynamic
MailAddress to = new MailAddress("toemail@domain.com");
MailAddress cc = new MailAddress("ccemail@domain.com");
MailMessage message = new MailMessage(from, to);
message.CC.Add(cc);
message.Body = txtEmailMsg.Text.ToString();
message.Subject = "Subject Goes Here";
client.SendAsync(message, userState);