Skip to main content

How To Send Email From Epicor Customization

To send an email from Epicor customization add the below code into the Epicor code editor.

-   Add the below namespace in the using section:

  using System.Net.Mail;

    -   Add the below code to send the email:

string mailServer = "SMTPMailServer";
MailMessage message = new MailMessage("from@YourCompany.com","to@YourCompany.com","Put the mail subject", "Message Body");
SmtpClient client = new SmtpClient(mailServer, 25);
client.Send(message);

Comments

  1. If this email message was to be triggered by a Button Click from a custom EpiButton on the Part Entry/Part Rev screen, how could you include some Part Number information in the email. For example, include the Part Number, Description, Revision Number, etc. currently showing on the screen within the email Message Body?

    ReplyDelete
    Replies
    1. You can include the part information in the email by getting a reference to the current row using EpiDataView as you can see below:

      EpiDataView partDv = (EpiDataView)oTrans.EpiDataViews["Part"];
      DataRow currRow = partDv .CurrentDataRow;
      if (currRow !=null)
      {
      // Here you can get any data from the current row
      MessageBox.Show("Part Number = "+currRow["PartNum"].ToString()+" "+"Part Description = "+ currRow["PartDescription"].ToString());
      }

      So by get a reference to the current row of part you can include any data. If you want to include any data from Part Rev you have to get a reference to the current row of the PartRev as below :

      EpiDataView partRevDv = (EpiDataView)oTrans.EpiDataViews["PartRev"];
      DataRow currRow = partRevDv .CurrentDataRow;
      if (currRow !=null)
      {
      // Here you can get any data from the current row
      MessageBox.Show("Part Number = "+currRow["PartNum"].ToString()+" "+"Revision Number = "+ currRow["RevisionNum"].ToString());
      }


      I hope this will help you.

      Delete
    2. Have you had any problems with this email being blocked by an anti-virus software? Mine only works if I disable the anti-virus...

      Delete
    3. No I donot have any problem with anti-virus.

      Delete
  2. Yes, that is very helpful. Thank you for the tip and prompt response. Best Regards

    ReplyDelete
  3. What is the different between BPM E-mail Template and the code you uploaded. I mean, Instead of using code why don't we use BPM Email Template.

    ReplyDelete
    Replies
    1. The BPM fires only when BO methods are called like (Update, GetNew,....) and using code you can send an email any time you want.

      So it depends on your requirements.

      Delete
  4. Thanks Waleed for the tip.
    I have a question: how to use your code to set an alert email that will send a notification email to the customer and his sales rep when he places an order? The email body will have the order_date, the partNum and the delivery_date.

    Thanks.

    ReplyDelete
  5. Thanks Waleed for the tip. I have a question: how to use your code to send notifications to the customer and the sales rep when he places an order? The email body will have the PartNum, OrderDate and DeliveryDate.

    Thanks..

    ReplyDelete
  6. Hi Waleed,
    is there any chance to add HTML tag to this kind of email?

    Antonio

    ReplyDelete
    Replies
    1. Yes, you can add HTML tag but you will use Alternative views.

      please refer to the below:

      https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.alternateviews(v=vs.110).aspx

      Delete

Post a Comment

Popular posts from this blog

Epicor 9 ToolBars

Like any other application, Epicor has list of toolbars and it uses the Infragistics controls and you can modify these toolbars in your code by adding new tools or change the properties for the existing toolbars and Tools.

How to Use the Business Activity Query Export Process

Business Activity Query Export Process let you export the BAQ data in XML or CSV format. You can export the BAQ data manually and you can schedule it to run automatically (Daily, Weekly, ,Monthly,Once,startup..etc) and you can configure this in the “system agent maintenance” and I will explain this later in this article.