E10- Send Email

Yes, you are right @markdamen. I was not there. Apologies if any thing is missing. I am discussing about UD screen customization. I am using below mention code

private void SendEmailApprover(string UserId, string Password, string EmailFrom, string Host, int Port, bool EnableSsl, string PONum, string EmailTo, string UserName)
{
SmtpClient smtpClient = new SmtpClient();
NetworkCredential basicCredential = new NetworkCredential(UserId, Password);
MailAddress fromAddress = new MailAddress(EmailFrom);
smtpClient.Host = Host;
smtpClient.Port = Port;
smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = basicCredential;
smtpClient.EnableSsl = EnableSsl;
MailMessage message = new MailMessage();
message.From = fromAddress;
message.Subject = “PO Approval”;
message.IsBodyHtml = true;
StringBuilder mailBody = new StringBuilder();
mailBody.AppendFormat(“Dear " + UserName);
mailBody.AppendFormat(”
“);
mailBody.AppendFormat(”

Please approve the Purchase Order: " + PONum + “

”);
mailBody.AppendFormat(“



”);
mailBody.AppendFormat(“

Thanks & Regards,

”);
mailBody.AppendFormat(“

Epicor Support

”);
mailBody.AppendFormat(“

***This is an automatically generated email – please do not reply to it. ***

”);
message.Body = mailBody.ToString();
message.To.Add(EmailTo);
try
{
smtpClient.Send(message);
}
catch(Exception ex)
{
ExceptionBox.Show(ex);
}
}

But, I want to use Epicor asynchronously email funcationality same like BPM in customization screen.
for eg.

var mailer = this.GetMailer(async: true);
var message = new Ice.Mail.SmtpMail();
message.SetFrom(“email@email.com”);
message.SetTo(“email1@email.com;email2@email.com”);
//message.SetCC()
//message.SetBcc()
message.SetBody(“

MyMessage Here

”);
Dictionary<string, string> attachments = new Dictionary<string, string>();
attachments.Add(“MyFirstAttachment”, @“\MyServer\myFolder\MyFile.pdf”);
mailer.Send(message, attachments);

You can still send mail asynchronously with an SmptClient class

But, with this you’ll lose any notification** of failure to send since it’s processing it async

**in the calling thread, that is

2 Likes

Dear Aaron,

Thanks for your reply. I know we can send asynchronously email using SMTP and Epicor BPM. But, I want to send email from customization screen using Epicor email functionality.

Is it possible. if possible then please share the code?

The best way to do that is to make a UD field in your customization, and set a BPM to watch for when that field changes to trigger the BPM. I think that’s how most people do it.

1 Like

This will require that the email settings are correct in your sysconfig file

EmailArgs args = new EmailArgs();
args.ToAddress = "Hari_Dutt@epiusers.help";
args.Subject = "Please format your code for the love of God!";
args.MessageBody = "Simply put ``` before and after your code it will make EVERYONE happier";
args.FromAddress = "EVERYONE@epiusers.help";
EmailHandler.SendMail(args);
7 Likes

Do you have a specific use case for needing to use the screen vs bpm? The reason we are asking is to save you time in the future when Kinetic is released, if you do it in BPM land you won’t have to re-write it (maybe minor tweaks) if you do it in customization land you will (write from scratch).

Dear Josecgomez,

Thanks for helping me. I really appreciate your kindness and support.
I have used the above code provided by you. After that system is throwing below error

Error Detail

Message: Failed to connect to SMTP server; Email attempt aborted. Please confirm the SMTP setting in the user settings element of the xxx.sysconfig AppSettings file.
Inner Exception Message: Failure sending mail.

After that, I opened the sysconfig file and enter the User Name, Password & SMTP server name (refer to attached screen)
image
But " Failure sending mail" message is coming.

I redacted your username, password, and server host please make sure not to include that info in screenshots for your own safety

1 Like

I dont think you can set a username and password on the sysconfig. You’ll have to have a relay @jgiese.wci @EarlGrei do you remember?

PS: @Hari_Dutt I really hope that’s not your password… I recommend changing it… STAT.

Depending on Epicor version you can set username and password directly but for overall ease in dealing with office 365 as a whole a relay is life.

1 Like

Dear jgiese,

For demo purpose, I have already enter the wrong password and email. Thanks for your suggestion.

1 Like

Yes josecgomez, it’s not the original email and password.

ok, regardless you can’t set that in the sysconfig you’ll have to have a relay setup. Or use what everyone else suggested and send email server side.

How to set email settings in sysconfig file & what are those settings ?

As I stated you cannot set username and password in the sysconfig. You will have to setup a relay.

Please let me know how to set up a relay?

This is like wayyyyyyyyyyyyyyyyyyyy beyond the scope friend. I think @EarlGrei has a post about it on here, but if you don’t know what it is or how to set it up it may be time to get someone to help (outside this forum) this is not an Epicor question is general IT and requires quite a bit of experience and know how.

2 Likes

I did a post about setting up a Relay (Office 365 in the example). No warranty or guarantees implied. Mileage may vary. LOL. Its how we do all of our email here. Give it a shot. If you are not sure what some of it is for then I agree that getting an IT Networking Professional involved is highly recommended.

3 Likes

Why would one have to rewrite it (cust) vs. not (BPM) after Kinetic is released?

Kinetic will be phased in and available in the .Net Client but I think what Josh is hinting at, someday there will be an all browser UI and those .Net customizations won’t have a place to run. Epicor will replace those “customizations” with the new Kinetic Studio.

One thing we’re going to have to do is get back to just doing UI mods in screen customizations and moving business logic back to the server - which isn’t a bad thing.

1 Like