Search code examples
c#emailsmtpclientnetworkcredentials

Sending an anonymous email to my own address


I want to send an anonymous email to my own gmail/hotmail/yahoo/any other mail service address (Im not trying to spam or something like that).

Why? I have a .NET application and I want to add a "Send log to the developer" feature (attaching the log) using SmtpClient. The fact is I've read like 30+ pages, and found out, i.e. gmail's smtp client doesn't allow anonymous connections, and many other things.

The idea is to receive a mail message like this:

From: [email protected] (non-existent email really)

To: [email protected] (this would be my real address which will recieve the logs attachments)

Subject: Issue report nºX (auto-generated)

Body: From a textbox

Attachments: logs attached

Is this possible? If so, how do I achieve it?


Solution

  • The short answer is that you can't reliably achieve this. You can get it to work in some cases, but not all.

    Most email servers these days have spam filters and rules for checking on emails, and in most cases an empty 'From' address will result in special treatment. Sometimes that just means a slightly higher spam score from the receiving mail server, but in some cases an empty 'From' address will result in your email being silently dropped in the bit bucket. You have no control over this, and neither will your users. It's all down to how the receiving mail server is configured.

    The simplest option is generally to allow the user to configure a from address and SMTP server. Some servers will require login to send messages, so you have to consider that. Many ISP mail servers (and most internal workplace mail servers) don't require login if the connection is coming from an address owned by the ISP (or workplace) and the email address is one that is registered as belonging there. Some ISPs - and this number is apparently growing - require SMTP login to send mail regardless.

    Another option is to set up a source domain, configure the SPF record for the domain to allow email from any IP address, and use a standard 'From' address in that domain. The downside to this is that once someone discovers that you've opened up a domain that way they'll start using it to send spam and you'll get shut down.

    There are many other options that have their own problems. One of the problems is that they generally cost money - some setup costs, most options also with ongoing costs - or open you up to liabilities of some sort.

    Give your users the choice. Let them try various options and see what works for them: no 'From' address, user-defined 'From' address (same as 'To' address is a good first try), partial SMTP login, full SMTP login, etc. If they don't trust your code enough to put their passwords in, let them create a throw-away account on gmail or something to run the messages through.