# E10- Send Email

**URL:** <https://www.epiusers.help/t/e10-send-email/54796>\
**Category:** Epicor ERP 10\
**Tags:** e10\
**Created:** [April 21, 2019, 9:30am UTC](https://www.epiusers.help/t/e10-send-email/54796 "2019-04-21T09:30:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hari\_Dutt](https://www.epiusers.help/user_avatar/www.epiusers.help/hari_dutt/32/17476_2.png) [@Hari\_Dutt](https://www.epiusers.help/u/Hari_Dutt)\
**Post date:** [April 21, 2019, 9:30am UTC](https://www.epiusers.help/t/e10-send-email/54796/1 "2019-04-21T09:30:50Z")

</div>

Dear Experts,

How to send email using  
Epicor.Mfg.UI.FrameWork.EmailHandler.SendMail in E10 (C# - Script Editor).

---

<div class="post-metadata">

**Author:** ![markdamen](https://www.epiusers.help/user_avatar/www.epiusers.help/markdamen/32/54917_2.png) [@markdamen](https://www.epiusers.help/u/markdamen)\
**Post date:** [April 21, 2019, 8:39pm UTC](https://www.epiusers.help/t/e10-send-email/54796/2 "2019-04-21T20:39:52Z")

</div>

I guess you weren’t in the session where @Banderson presented about how to best ask questions on this forum to get decent, full answers.

You haven’t specified whether you’re talking screen customization, or BPM. What code do you already have that isn’t working? If you have something, post it up so that we can assist. If you don’t already have anything, then please search the forum - there are plenty of posts showing how to email from code already.

---

<div class="post-metadata">

**Author:** ![Hari\_Dutt](https://www.epiusers.help/user_avatar/www.epiusers.help/hari_dutt/32/17476_2.png) [@Hari\_Dutt](https://www.epiusers.help/u/Hari_Dutt)\
**Post date:** [April 22, 2019, 4:49am UTC](https://www.epiusers.help/t/e10-send-email/54796/3 "2019-04-22T04:49:02Z")

</div>

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](mailto:email@email.com)”);  
message.SetTo(“[email1@email.com](mailto:email1@email.com);email2@email.com”);  
[//message.SetCC](https://message.SetCC)()  
[//message.SetBcc](https://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);

---

<div class="post-metadata">

**Author:** ![Aaron\_Moreng](https://www.epiusers.help/user_avatar/www.epiusers.help/aaron_moreng/32/745_2.png) [@Aaron\_Moreng](https://www.epiusers.help/u/Aaron_Moreng)\
**Post date:** [April 22, 2019, 2:40pm UTC](https://www.epiusers.help/t/e10-send-email/54796/4 "2019-04-22T14:40:06Z")

</div>

You can still send mail asynchronously with an SmptClient class

> **[SmtpClient.SendAsync Method (System.Net.Mail)](https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.smtpclient.sendasync?view=netframework-4.8)**
>
> Sends an email message. These methods do not block the calling thread.

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

\*\*in the calling thread, that is

---

<div class="post-metadata">

**Author:** ![Hari\_Dutt](https://www.epiusers.help/user_avatar/www.epiusers.help/hari_dutt/32/17476_2.png) [@Hari\_Dutt](https://www.epiusers.help/u/Hari_Dutt)\
**Post date:** [April 24, 2019, 7:21am UTC](https://www.epiusers.help/t/e10-send-email/54796/5 "2019-04-24T07:21:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Banderson](https://www.epiusers.help/user_avatar/www.epiusers.help/banderson/32/50875_2.png) [@Banderson](https://www.epiusers.help/u/Banderson)\
**Post date:** [April 24, 2019, 12:59pm UTC](https://www.epiusers.help/t/e10-send-email/54796/6 "2019-04-24T12:59:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![josecgomez](https://www.epiusers.help/user_avatar/www.epiusers.help/josecgomez/32/55731_2.png) [@josecgomez](https://www.epiusers.help/u/josecgomez)\
**Post date:** [April 24, 2019, 1:05pm UTC](https://www.epiusers.help/t/e10-send-email/54796/7 "2019-04-24T13:05:30Z")

</div>

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

````auto
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);

````

---

<div class="post-metadata">

**Author:** ![jgiese.wci](https://www.epiusers.help/user_avatar/www.epiusers.help/jgiese.wci/32/51553_2.png) [@jgiese.wci](https://www.epiusers.help/u/jgiese.wci)\
**Post date:** [April 24, 2019, 1:21pm UTC](https://www.epiusers.help/t/e10-send-email/54796/8 "2019-04-24T13:21:44Z")

</div>

> [@Hari\_Dutt](#):
>
> But, I want to send email from customization screen using Epicor email functionality.

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).

---

<div class="post-metadata">

**Author:** ![Hari\_Dutt](https://www.epiusers.help/user_avatar/www.epiusers.help/hari_dutt/32/17476_2.png) [@Hari\_Dutt](https://www.epiusers.help/u/Hari_Dutt)\
**Post date:** [April 24, 2019, 1:48pm UTC](https://www.epiusers.help/t/e10-send-email/54796/9 "2019-04-24T13:48:24Z")

</div>

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](https://epiusers.help/uploads/default/original/3X/2/5/2559c2a7660feda3b880dc4890261bb219be8050.png)  
But " Failure sending mail" message is coming.

---

<div class="post-metadata">

**Author:** ![jgiese.wci](https://www.epiusers.help/user_avatar/www.epiusers.help/jgiese.wci/32/51553_2.png) [@jgiese.wci](https://www.epiusers.help/u/jgiese.wci)\
**Post date:** [April 24, 2019, 1:52pm UTC](https://www.epiusers.help/t/e10-send-email/54796/10 "2019-04-24T13:52:06Z")

</div>

> [@Hari\_Dutt](#):
>
> (refer to attached screen)

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

---

<div class="post-metadata">

**Author:** ![josecgomez](https://www.epiusers.help/user_avatar/www.epiusers.help/josecgomez/32/55731_2.png) [@josecgomez](https://www.epiusers.help/u/josecgomez)\
**Post date:** [April 24, 2019, 1:52pm UTC](https://www.epiusers.help/t/e10-send-email/54796/11 "2019-04-24T13:52:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jgiese.wci](https://www.epiusers.help/user_avatar/www.epiusers.help/jgiese.wci/32/51553_2.png) [@jgiese.wci](https://www.epiusers.help/u/jgiese.wci)\
**Post date:** [April 24, 2019, 1:53pm UTC](https://www.epiusers.help/t/e10-send-email/54796/12 "2019-04-24T13:53:05Z")

</div>

> [@josecgomez](#):
>
> You’ll have to have a relay

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.

---

<div class="post-metadata">

**Author:** ![Hari\_Dutt](https://www.epiusers.help/user_avatar/www.epiusers.help/hari_dutt/32/17476_2.png) [@Hari\_Dutt](https://www.epiusers.help/u/Hari_Dutt)\
**Post date:** [April 24, 2019, 1:55pm UTC](https://www.epiusers.help/t/e10-send-email/54796/13 "2019-04-24T13:55:41Z")

</div>

Dear jgiese,

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

---

<div class="post-metadata">

**Author:** ![Hari\_Dutt](https://www.epiusers.help/user_avatar/www.epiusers.help/hari_dutt/32/17476_2.png) [@Hari\_Dutt](https://www.epiusers.help/u/Hari_Dutt)\
**Post date:** [April 24, 2019, 1:57pm UTC](https://www.epiusers.help/t/e10-send-email/54796/14 "2019-04-24T13:57:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![josecgomez](https://www.epiusers.help/user_avatar/www.epiusers.help/josecgomez/32/55731_2.png) [@josecgomez](https://www.epiusers.help/u/josecgomez)\
**Post date:** [April 24, 2019, 1:58pm UTC](https://www.epiusers.help/t/e10-send-email/54796/15 "2019-04-24T13:58:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Hari\_Dutt](https://www.epiusers.help/user_avatar/www.epiusers.help/hari_dutt/32/17476_2.png) [@Hari\_Dutt](https://www.epiusers.help/u/Hari_Dutt)\
**Post date:** [April 24, 2019, 1:59pm UTC](https://www.epiusers.help/t/e10-send-email/54796/16 "2019-04-24T13:59:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![josecgomez](https://www.epiusers.help/user_avatar/www.epiusers.help/josecgomez/32/55731_2.png) [@josecgomez](https://www.epiusers.help/u/josecgomez)\
**Post date:** [April 24, 2019, 2:02pm UTC](https://www.epiusers.help/t/e10-send-email/54796/17 "2019-04-24T14:02:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Hari\_Dutt](https://www.epiusers.help/user_avatar/www.epiusers.help/hari_dutt/32/17476_2.png) [@Hari\_Dutt](https://www.epiusers.help/u/Hari_Dutt)\
**Post date:** [April 24, 2019, 2:03pm UTC](https://www.epiusers.help/t/e10-send-email/54796/18 "2019-04-24T14:03:51Z")

</div>

Please let me know how to set up a relay?

---

<div class="post-metadata">

**Author:** ![josecgomez](https://www.epiusers.help/user_avatar/www.epiusers.help/josecgomez/32/55731_2.png) [@josecgomez](https://www.epiusers.help/u/josecgomez)\
**Post date:** [April 24, 2019, 2:08pm UTC](https://www.epiusers.help/t/e10-send-email/54796/19 "2019-04-24T14:08:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![EarlGrei](https://www.epiusers.help/user_avatar/www.epiusers.help/earlgrei/32/21009_2.png) [@EarlGrei](https://www.epiusers.help/u/EarlGrei)\
**Post date:** [April 24, 2019, 2:16pm UTC](https://www.epiusers.help/t/e10-send-email/54796/20 "2019-04-24T14:16:17Z")

</div>

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.

> **[Multilple E-mails without anonymous authentication](https://www.epiusers.help/t/multilple-e-mails-without-anonymous-authentication/44977/20)**
>
> Please read this carefully and pay attention to the warning at the bottom. I did this entire thing from memory and its been a while since I have set one up but I am pretty sure I got everything. Let me know if you have any issues and if it works...

[Next page](https://www.epiusers.help/t/e10-send-email/54796.md?page=2)
