I'm building a C # application on Visual.NET.

Now, After packing program to deployment. When users use the program, if have internet connection, the program will automatically send mail notification to me.

To do that I do like?

Thanks!

Have you looked up using System.Net.Mail; ?
http://msdn.microsoft.com/en-us/library/system.net.mail.aspx

How about SmtpClient.Send();
http://msdn.microsoft.com/en-us/library/h1s04he7.aspx#Y0

You will need to have a server that will let you send anonymous mail (or embed an account inside the program (bad idea)).

Be sure you have the users permission to send the mail.
Maybe you could mention it in a disclaimer or End User License Agreement.

That way, you can protect your reputation and the reputation of your company.
People can sniff your compiled code for the signature that will tell them something is happening in the background.

Some of us really dislike programs "calling home" when they are used.

First I would like to thank your suggest. My idea aims to capture user actions to improve program because my software in the testing period. Of course I shall let the user choice of End User License Agreement.

You did not try for that purpose "Calling home when using program". And can you provide me sample code?

Thanks!

Some of this will depend on the type of SMTP server you're using.

using System;
using System.Net.Mail;

//...

public static bool SendMail(string strEmailToFrom, string strBody)
      {
         bool blnRetVal = true;
         try
         {
            SmtpClient smtp = new SmtpClient("222.33.44.5");//smtp server address
            MailMessage msg = new MailMessage();
            msg.To.Add(strEmailToFrom);
            MailAddress mailAddrFrom = new MailAddress(strEmailToFrom);
            msg.From = mailAddrFrom;
            msg.Subject = "Test Send Mail";
            msg.Body = strBody;
            smtp.Send(msg);
         }
         catch (Exception)
         {
            blnRetVal = false;
         }

         return blnRetVal;
      }

Here is a technique for sending through GMail.
Remember, your GMail settings might need to be modified to allow POP/SMTP access.

using System;
using System.Net;
using System.Net.Mail;

namespace SendGMailCs
{
   using GetCred; // My personal credential repository
   class Program
   {
      public static bool SendMail(NetworkCredential cred, string strSubject, string strEmailTo, string strBody, string strFileAttach, ref string strError)
      {
         bool blnRetVal = true;
         try
         {
            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
            smtp.EnableSsl = true;
            //
            MailMessage msg = new MailMessage();
            if(!string.IsNullOrEmpty(strFileAttach))
            {
               msg.Attachments.Add(new Attachment(strFileAttach));
            }
            msg.To.Add(strEmailTo);
            msg.From = new MailAddress(cred.UserName);
            msg.Subject = strSubject;
            msg.IsBodyHtml = true;
            msg.Body = strBody;
            //msg->Priority = MailPriority::High;
            cred.Domain = "";
            smtp.Credentials = cred;
            smtp.Send(msg);
         }
         catch (Exception exc)
         {
            blnRetVal = false;
            strError = exc.Message;
         }

         return blnRetVal;
      }

      static void Main(string[] args)
      {
         NetworkCredential cred = CGetCred.GetCred("GMAIL");
         
         string strError = "";

         if (!SendMail(
            cred, // Network Credential (user ID used as from address)
            "Test mail from code", // Subject
            cred.UserName, // TO email address blah@blah.com
            "body of message", // Message Body
            "", // Path to file attachment
            ref strError // return content of any error
            ))
         {
            Console.WriteLine("Could not send: " + strError);
            return;
         }

         Console.WriteLine("Finished");
      }
   }
}

Edited 4 Years Ago by thines01: converted tabs

Hi thines01,

The code above means of sending email. Not only that we also need to check the internet connection status, using the application status (Is program begin?), a user's computer information?

You could simply wrap that in a try/catch block.
There are more things that can go wrong with sending mail than JUST the Internet connection such as firewall blocking or a poor connection, retries, etc.

You could write a lot of code to try to get around all of the possibilities or you could just try once and ignore any errors.

try
{
   //call the send-mail rountine
}
catch(Exception)
{
   //ignore any error
}

Edited 4 Years Ago by thines01: clarity

This question has already been answered. Start a new discussion instead.