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);
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?
ReplyDeleteYou can include the part information in the email by getting a reference to the current row using EpiDataView as you can see below:
DeleteEpiDataView 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.
Have you had any problems with this email being blocked by an anti-virus software? Mine only works if I disable the anti-virus...
DeleteNo I donot have any problem with anti-virus.
DeleteYes, that is very helpful. Thank you for the tip and prompt response. Best Regards
ReplyDeleteYour Welcome.
DeleteWhat 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.
ReplyDeleteThe BPM fires only when BO methods are called like (Update, GetNew,....) and using code you can send an email any time you want.
DeleteSo it depends on your requirements.
Thanks Waleed for the tip.
ReplyDeleteI 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.
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.
ReplyDeleteThanks..
Hi Waleed,
ReplyDeleteis there any chance to add HTML tag to this kind of email?
Antonio
Yes, you can add HTML tag but you will use Alternative views.
Deleteplease refer to the below:
https://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.alternateviews(v=vs.110).aspx