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!
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!
Short practical guidance for adding “call‑home” reporting to a deployed C# app (thanks to for the SMTP pointers and for the test/telemetry use case).
Keep it server-side when possible. Have the client POST small, anonymized telemetry to a secure HTTPS endpoint that you control; the server can authenticate, validate, rate‑limit and send email (or store events) so no SMTP credentials are shipped in the distributed binary. Example client pattern (minimal):
using var client = new HttpClient();
var body = JsonSerializer.Serialize(new { event="start", when=DateTime.UtcNow, version="1.0.0" });
var content = new StringContent(body, Encoding.UTF8, "application/json");
await client.PostAsync("https://telemetry.example.com/api/events", content); If you must send directly from the client (not recommended for production), avoid embedding long‑lived credentials and prefer a modern library such as MailKit instead of System.Net.Mail/SmtpClient; Microsoft’s docs note SmtpClient isn’t recommended for new development. (learn.microsoft.com)
Provider policies matter: Gmail and Google Workspace have removed (or are removing) “less secure app” password access — you’ll need OAuth2 or an app‑specific password where available, not plain username/password in many accounts. Plan for that if you intended to use smtp.gmail.com. (workspaceupdates.googleblog.com)
Reliability notes: queue unsent reports locally (file/SQLite), send on a background thread, use exponential backoff and a max retry count, and probe actual connectivity with a lightweight HTTP request rather than relying solely on NetworkInterface.GetIsNetworkAvailable(). (learn.microsoft.com)
Privacy and UX: make reporting explicit (EULA/opt‑in or clear settings), keep payloads minimal, and offer an easy opt‑out. For test builds, include a diagnostics toggle and clear text explaining what is collected. This approach protects users and reduces legal/privacy risk while still giving useful telemetry during your testing period.
Jump to Post— thines01 401Have you looked up using System.Net.Mail; ?
http://msdn.microsoft.com/en-us/library/system.net.mail.aspxHow about SmtpClient.Send();
http://msdn.microsoft.com/en-us/library/h1s04he7.aspx#Y0You will need to …
Jump to Post— thines01 401Some 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(); …
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");
}
}
} 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
} Thanks thines01!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.