Email via C# Blank Title 127619

Wow, too easy.  Thanks Jose!

I normally use the wonderful ABL email code provided by this group, but today I need to do the same thing only via C#.  I searched but couldn’t find an existing string for C#.  Does anyone have that code handy?  Please….

 

Brenda

 

Google is your best friend on this one. There are all sorts of great resources on the world wide web for C# and using System.Net.Mail. Find a stackoverflow.com post or something for that and you should be able to get the gist.

 

Joshua Giese

CIO

920.437.6400 Ext. 337

Site ID: 27450-E905700B2-SQL64

Wisconsin Converting, Inc.

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of brenda mohr
Sent: Wednesday, January 15, 2014 2:07 PM
To: vantage@yahoogroups.com
Subject: [Vantage] Email via C#

 

 

I normally use the wonderful ABL email code provided by this group, but today I need to do the same thing only via C#.  I searched but couldn’t find an existing string for C#.  Does anyone have that code handy?  Please….

 

Brenda

 

Brenda –

 

The below code is from Microsoft’s site.

 

Hope this helps:

using System;

using System.Net;

using System.Net.Mail;

using System.Net.Mime;

using System.Threading;

using System.ComponentModel;

namespace Examples.SmptExamples.Async

{

    public class SimpleAsynchronousExample

    {

        static bool mailSent = false;

        private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)

        {

            // Get the unique identifier for this asynchronous operation.

             String token = (string) e.UserState;

 

            if (e.Cancelled)

            {

                 Console.WriteLine("[{0}] Send canceled.", token);

            }

            if (e.Error != null)

            {

                 Console.WriteLine("[{0}] {1}", token, e.Error.ToString());

            } else

            {

                Console.WriteLine("Message sent.");

            }

            mailSent = true;

        }

        public static void Main(string[] args)

        {

            // Command line argument must the the SMTP host.

            SmtpClient client = new SmtpClient(args[0]);

            // Specify the e-mail sender. 

            // Create a mailing address that includes a UTF8 character 

            // in the display name.

            MailAddress from = new MailAddress("jane@...",

               "Jane " + (char)0xD8+ " Clayton",

            System.Text.Encoding.UTF8);

            // Set destinations for the e-mail message.

            MailAddress to = new MailAddress("ben@...");

            // Specify the message content.

            MailMessage message = new MailMessage(from, to);

            message.Body = "This is a test e-mail message sent by an application. ";

            // Include some non-ASCII characters in body and subject. 

            string someArrows = new string(new char[] {'\u2190', '\u2191', '\u2192', '\u2193'});

            message.Body += Environment.NewLine + someArrows;

            message.BodyEncoding =  System.Text.Encoding.UTF8;

            message.Subject = "test message 1" + someArrows;

            message.SubjectEncoding = System.Text.Encoding.UTF8;

            // Set the method that is called back when the send operation ends.

            client.SendCompleted += new

            SendCompletedEventHandler(SendCompletedCallback);

            // The userState can be any object that allows your callback  

            // method to identify this send operation. 

            // For this example, the userToken is a string constant. 

            string userState = "test message1";

            client.SendAsync(message, userState);

            Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");

            string answer = Console.ReadLine();

            // If the user canceled the send, and mail hasn't been sent yet, 

            // then cancel the pending operation. 

            if (answer.StartsWith("c") && mailSent == false)

            {

                client.SendAsyncCancel();

            }

            // Clean up.

            message.Dispose();

            Console.WriteLine("Goodbye.");

        }

    }

}

 

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of brenda mohr
Sent: Wednesday, January 15, 2014 2:07 PM
To: vantage@yahoogroups.com
Subject: [Vantage] Email via C#

 

 

I normally use the wonderful ABL email code provided by this group, but today I need to do the same thing only via C#.  I searched but couldn’t find an existing string for C#.  Does anyone have that code handy?  Please….

 

Brenda

 

Thank You Calvin,

 

This gives me a good place to start. 

 

Brenda

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of Calvin Dekker
Sent: Thursday, January 16, 2014 10:10 AM
To: vantage@yahoogroups.com
Subject: [Vantage] RE: Email via C#

 

 

Brenda –

 

The below code is from Microsoft’s site.

 

Hope this helps:

using System;

using System.Net;

using System.Net.Mail;

using System.Net.Mime;

using System.Threading;

using System.ComponentModel;

namespace Examples.SmptExamples.Async

{

    public class SimpleAsynchronousExample

    {

        static bool mailSent = false;

        private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)

        {

            // Get the unique identifier for this asynchronous operation.

             String token = (string) e.UserState;

 

            if (e.Cancelled)

            {

                 Console.WriteLine("[{0}] Send canceled.", token);

            }

            if (e.Error != null)

            {

                 Console.WriteLine("[{0}] {1}", token, e.Error.ToString());

            } else

            {

                Console.WriteLine("Message sent.");

            }

            mailSent = true;

        }

        public static void Main(string[] args)

        {

            // Command line argument must the the SMTP host.

            SmtpClient client = new SmtpClient(args[0]);

            // Specify the e-mail sender. 

            // Create a mailing address that includes a UTF8 character 

            // in the display name.

            MailAddress from = new MailAddress("jane@...",

               "Jane " + (char)0xD8+ " Clayton",

            System.Text.Encoding.UTF8);

            // Set destinations for the e-mail message.

            MailAddress to = new MailAddress("ben@...");

            // Specify the message content.

            MailMessage message = new MailMessage(from, to);

            message.Body = "This is a test e-mail message sent by an application. ";

            // Include some non-ASCII characters in body and subject. 

            string someArrows = new string(new char[] {'\u2190', '\u2191', '\u2192', '\u2193'});

Are you trying to send am email via epicor using C#?

  Private Sub SendEmail(ByVal pro as DataTable)
   
        dim info as string()
   
            'send e-mails...
        dim comp as new Epicor.Mfg.BO.Company(oTrans.Session.ConnectionPool)
        dim compDS as Epicor.Mfg.BO.CompanyDataSet = comp.GetByID(oTrans.Session.CompanyID)       
        dim client as new SmtpClient(compDS.Company(0).SmtpServer, compDS.Company(0).SmtpPort)
       
        'Dim SmtpUser As New System.Net.NetworkCredential()

        'setup the domain credentials
        'SmtpUser.Domain = EmailDomain
        'SmtpUser.Password = EmailPassword
        'SmtpUser.UserName = EmailUserName

        'set the domain credentials to the smtp object
        client.UseDefaultCredentials = True
        'client.Credentials = SmtpUser
       
        dim mail as MailMessage = new MailMessage(compDS.Company(0).EmailFromAddr, EmailTo)
       
        mail.Subject = EmailSubject
        mail.IsBodyHtml = true
       
        dim sb as new System.Text.StringBuilder()
       
        if pro.Select("OrderNum > 0").Length > 0 then
            sb.Append("The following orders were genereted by the SO Inbound Process:<br /><br />")
           
            dim dv as new DataView(pro)
            dv.RowFilter = "OrderNum > 0"
            for each dr as DataRow in dv.ToTable(true, "OrderNum".Split(",")).Rows
                sb.Append(dr("OrderNum").ToString()).Append("<br />")
            next
           
        end if
       
        if errors.Count > 0 then
            sb.Append("<br /><br />There were some errors while attempting to import some of the data. Attached is also a file with the error lines.  Please correct the errors in the file and place into the processing directory to re-process the lines. Please see below for further information:<br /><br />")
            sb.Append("<table><tr><td><b>Part Number</b></td><td><b>Line</b></td><td><b>File Name</b></td><td><b>Error</b></td></tr>")         
           
            for each str as string in errors
                info = str.Split("~")
               
                sb.Append("<tr><td>").Append(info(0)).Append("</td><td>").Append(info(1)).Append("</td><td>").Append(info(2)).Append("</td><td>").Append(info(3)).Append("</td></tr>")
            next
           
            sb.Append("</table>")
       
            dim bad as new System.Text.StringBuilder()
       
            bad.Append("Customercode,WhseCode,ErpPo,Partnumber,QtyOrdered,Line,OrderedPrice,NeedBy,ShipBy,ErrorReason")           
       
            for each dr as DataRow in pro.Select("OrderNum = 0")
                bad.Append(vbCrLf).Append(dr("CustID").ToString()).Append(",").Append(dr("Warehouse").ToString()).Append(",").Append(dr("PO").ToString()).Append(",")
                bad.Append(dr("PartNum").ToString()).Append(",").Append(dr("Qty").ToString()).Append(",").Append(dr("Line").ToString()).Append(",")
                bad.Append(dr("Price").ToString()).Append(",")
                try
                    bad.Append(DateTime.Parse(dr("NeedBy").ToString()).ToString("MM/dd/yyyy")).Append(",")
                catch
                    bad.Append(",")
                end try
               
                try
                    bad.Append(DateTime.Parse(dr("ShipBy").ToString()).ToString("MM/dd/yyyy")).Append(",")
                catch
                    bad.Append(",")
                end try
               
                bad.Append("""").Append(dr("ErrorReason").ToString()).Append("""")             
               
            next
           
            Dim data As Byte() = Encoding.ASCII.GetBytes(bad.ToString())
           
            dim ms as New System.IO.MemoryStream(data)

            Dim attach As New System.Net.Mail.Attachment(ms, "SOInboundErrorFile-" + DateTime.Now.ToString("MM-dd-yyyy-hh-mm") + ".csv", "text/plain")

            mail.Attachments.Add(attach)
           
        end if
       
        mail.Body = sb.ToString()
       
        'if there are no rows, then do not send an e-mail
        if pro.Rows.Count > 0 then
            client.Send(mail)
        end if
   
    End Sub

Here is an easier way

Epicor has a built in email functionality that you can use on the forms if you go to the File -> Send Record by Email, I looked under the hood, why re-invent the wheel?


Epicor.Mfg.UI.FrameWork.EmailArgs a = new Epicor.Mfg.UI.FrameWork.EmailArgs();
a.FromAddress="thisis@…";
a.ToAddress="yeah@…";
a.Subject="Hello";
a.MessageBody="This is the Body";
Epicor.Mfg.UI.FrameWork.EmailHandler.SendMail(a);



Jose C Gomez

Software Engineer


T: 904.469.1524 mobile

E: jose@…

http://www.josecgomez.com
     Â


Quis custodiet ipsos custodes?


On Thu, Jan 16, 2014 at 10:34 AM, <cyrilz199@...> wrote:

Â
<div>
  
  
  <p></p><p>Are you trying to send am email via epicor using C#?<var></var></p><p></p>

</div>
 


<div style="color:#fff;min-height:0;"></div>

Nice!

 

We have to get special permissions from our Systems group in order to send out emails programmatically from a client machine.  I can’t remember the errors specifically but, if you know everything is right but, things are still failing, it’s something you may need to look at.

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of Jose Gomez
Sent: Thursday, January 16, 2014 10:53 AM
To: Vantage
Subject: Re: [Vantage] RE: Email via C#

 

 

Here is an easier way

 

Epicor has a built in email functionality that you can use on the forms if you go to the File -> Send Record by Email, I looked under the hood, why re-invent the wheel?

 

Epicor.Mfg.UI.FrameWork.EmailArgs a = new Epicor.Mfg.UI.FrameWork.EmailArgs(); a.FromAddress="thisis@..."; a.ToAddress="yeah@..."; a.Subject="Hello"; a.MessageBody="This is the Body"; Epicor.Mfg.UI.FrameWork.EmailHandler.SendMail(a);



Jose C Gomez

Software Engineer

 


T: 904.469.1524 mobile


Quis custodiet ipsos custodes?

 

On Thu, Jan 16, 2014 at 10:34 AM, <cyrilz199@...> wrote:

 

Are you trying to send am email via epicor using C#?

 

Very nice to know Jose! Out of curiosity is it possible to send attachments this way?

Yes just pass it a string array of the file names you want to attach. The Property is Attachments



Jose C Gomez
Software Engineer



T: 904.469.1524 mobile
E: jose@...
http://www.josecgomez.com

     Â


Quis custodiet ipsos custodes?


On Thu, Jan 16, 2014 at 12:00 PM, <don.n.doan@...> wrote:

Â
<div>
  
  
  <p></p><p>Very nice to know Jose! Out of curiosity is it possible to send attachments this way?</p><p></p>

</div>
 


<div style="color:#fff;min-height:0;"></div>

Reading this thread now after working through using Outlook to send emails.  I could have used the Epicor internal client, but just like emailing with BPMs it does not allow the user an easy way to prove the email was sent.  But I suppose you could CC or BCC the user so they got a copy in their email in their inbox.  This may have saved me a bit of time avoiding formatting issues I had with the HTML emails I created. :(

Cheers
Simon Hall

Joe, Would you be able to specify on that permissions problem you were having?

Our Systems group has locked things down to make sure that our internal pcs can’t become spam bots by preventing programmatically generated emails from leaving the domain.  It’s been a couple of years so, I really can’t remember how the problem showed up for me and how I was finally able to blame our systems group.  Sorry about that.

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of don.n.doan@...
Sent: Tuesday, January 21, 2014 5:49 PM
To: vantage@yahoogroups.com
Subject: [Vantage] RE: Email via C#

 

 

Joe, Would you be able to specify on that permissions problem you were having?

They should just have to allow your Epicor server to relay through your email server. Pretty easy setting. We do it that way here for the same spam bot reason listed below.



Sent from my Atari 600



-----Original Message-----

From: Joe Englert [englertj@…]

Received: Wednesday, 22 Jan 2014, 5:17

To: vantage@yahoogroups.com [vantage@yahoogroups.com]

Subject: RE: [Vantage] RE: Email via C#



 

Our Systems group has locked things down to make sure that our internal pcs can’t become spam bots by preventing programmatically generated emails from leaving the domain.  It’s been a couple of years so, I really can’t remember how the problem showed up for me and how I was finally able to blame our systems group.  Sorry about that.

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of don.n.doan@...
Sent: Tuesday, January 21, 2014 5:49 PM
To: vantage@yahoogroups.com
Subject: [Vantage] RE: Email via C#

 

 

Joe, Would you be able to specify on that permissions problem you were having?

Not talking Epicor Server, talking Epicor client.

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of Joshua Giese
Sent: Wednesday, January 22, 2014 7:24 AM
To: vantage@yahoogroups.com
Subject: RE: [Vantage] RE: Email via C#

 

 

They should just have to allow your Epicor server to relay through your email server. Pretty easy setting. We do it that way here for the same spam bot reason listed below.

Sent from my Atari 600

-----Original Message-----
From: Joe Englert [englertj@...]
Received: Wednesday, 22 Jan 2014, 5:17
To: vantage@yahoogroups.com [vantage@yahoogroups.com]
Subject: RE: [Vantage] RE: Email via C#

 

Our Systems group has locked things down to make sure that our internal pcs can’t become spam bots by preventing programmatically generated emails from leaving the domain.  It’s been a couple of years so, I really can’t remember how the problem showed up for me and how I was finally able to blame our systems group.  Sorry about that.

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of don.n.doan@...
Sent: Tuesday, January 21, 2014 5:49 PM
To: vantage@yahoogroups.com
Subject: [Vantage] RE: Email via C#

 

 

Joe, Would you be able to specify on that permissions problem you were having?

The clients? There are quite a few different ways to send email without doing it from the client. What is the requirement that is forcing that?

 

Joshua Giese

CIO

920.437.6400 Ext. 337

Site ID: 27450-E905700B2-SQL64

Wisconsin Converting, Inc.

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of Joe Englert
Sent: Wednesday, January 22, 2014 6:34 AM
To: vantage@yahoogroups.com
Subject: RE: [Vantage] RE: Email via C#

 

 

Not talking Epicor Server, talking Epicor client.

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of Joshua Giese
Sent: Wednesday, January 22, 2014 7:24 AM
To: vantage@yahoogroups.com
Subject: RE: [Vantage] RE: Email via C#

 

 

They should just have to allow your Epicor server to relay through your email server. Pretty easy setting. We do it that way here for the same spam bot reason listed below.

Sent from my Atari 600

-----Original Message-----
From: Joe Englert [englertj@...]
Received: Wednesday, 22 Jan 2014, 5:17
To: vantage@yahoogroups.com [vantage@yahoogroups.com]
Subject: RE: [Vantage] RE: Email via C#

 

Our Systems group has locked things down to make sure that our internal pcs can’t become spam bots by preventing programmatically generated emails from leaving the domain.  It’s been a couple of years so, I really can’t remember how the problem showed up for me and how I was finally able to blame our systems group.  Sorry about that.

 

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of don.n.doan@...
Sent: Tuesday, January 21, 2014 5:49 PM
To: vantage@yahoogroups.com
Subject: [Vantage] RE: Email via C#

 

 

Joe, Would you be able to specify on that permissions problem you were having?

Others have gotten around this problem by installing an STMP server which forwards the email to your main mail server. You give permission to the local SMTP server to route out through the main mail server and give permission for the local SMTP to receive main from your internal IP addresses using local permission of some kind to prevent viruses from spamming people.


On Wed, Jan 22, 2014 at 7:34 AM, Joe Englert <englertj@...> wrote:

Â
<div>
  
  
  <p>

Not talking Epicor Server, talking Epicor client.

Â

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of Joshua Giese
Sent: Wednesday, January 22, 2014 7:24 AM
To: vantage@yahoogroups.com


Subject: RE: [Vantage] RE: Email via C#

Â

Â

They should just have to allow your Epicor server to relay through your email server. Pretty easy setting. We do it that way here for the same spam bot reason listed below.

Sent from my Atari 600

-----Original Message-----
From: Joe Englert [englertj@...]
Received: Wednesday, 22 Jan 2014, 5:17
To: vantage@yahoogroups.com [vantage@yahoogroups.com]
Subject: RE: [Vantage] RE: Email via C#

Â

Our Systems group has locked things down to make sure that our internal pcs can’t become spam bots by preventing programmatically generated emails from leaving the domain. It’s been a couple of years so, I really can’t remember how the problem showed up for me and how I was finally able to blame our systems group. Sorry about that.

Â

From: vantage@yahoogroups.com [mailto:vantage@yahoogroups.com] On Behalf Of don.n.doan@...
Sent: Tuesday, January 21, 2014 5:49 PM
To: vantage@yahoogroups.com
Subject: [Vantage] RE: Email via C#

Â

Â

Joe, Would you be able to specify on that permissions problem you were having?

</div>
 


<div style="color:#fff;min-height:0;"></div>

It looks like the client mfgsys config file needs to be set with the SMTP server.  After I did that it worked, however now if I want to have this working on all clients i'd have to update their mfgsys.  


Another question for you gurus, do you know how to re-create that attachment of the mfgsys file being emailed through vb or c#?  I could see that shortcut file coming in handy in a few situations(without the user actually having to send it manually through Epicor).

Take the file save it to a network locatin openit it up (its XML) re-create it. TADA! :-)



Jose C Gomez
Software Engineer



T: 904.469.1524 mobile
E: jose@...
http://www.josecgomez.com

     Â


Quis custodiet ipsos custodes?


On Fri, Jan 24, 2014 at 9:48 AM, <don.n.doan@...> wrote:

Â
<div>
  
  
  <p></p><p>It looks like the client mfgsys config file needs to be set with the SMTP server. Â After I did that it worked, however now if I want to have this working on all clients i&#39;d have to update their mfgsys. Â </p>


Another question for you gurus, do you know how to re-create that attachment of the mfgsys file being emailed through vb or c#? Â I could see that shortcut file coming in handy in a few situations(without the user actually having to send it manually through Epicor).

</div>
 


<div style="color:#fff;min-height:0;"></div>