I would like my program to email me a bug-report when it fails. Is there any way of doing this... safely? I have found I can use System.Net.Mail MailMessage and SmtpClient and such, but of course, I will have to provide a username and a password to it (unless someone knows of one that doesn't need it?). And putting that in code I find a bit... I don't know. Technically it would mean that anyone could look at the source code or the compiled IL code (or what it was called) and find that username and password and use it for spamming or other not so good activites. Which is not very good!
Any ideas? Is there a better and/or different approach to this problem? Doesn't really have to be through email. But what I want is a way for the program to notify when something happens that I should fix. And to make that notification as little troublesome as possible to the user. Maybe even invisible (although a YesNo messagebox might be polite).
Anyone?
Instead of sending mail you could set up a web service that would receive the reports. The web service could run over https if you want to protect the data.
I did this for a customer once and it worked well.
The only problem is if the program is running somewhere without internet access.
Edit:
Don't tell this to anyone, but we even took a screenshot of the program when it crashed and posted it together with all information about the error that we could gather. It was incredibly useful!
You don't need to provide your password to email to yourself, as you don't need other people's password to send email to them.
You only need a password if you relay an email over a third party's SMTP server.
If your SMTP client connects right to example.com on port 25 and sends an email to test#example.com, no password is needed.
example.com above means an MX record, not an A record. This is a special type of record that holds the name of the server where all emails for example.com should go. There is no easy way to look it up from .NET, but if you are not going to change your SMTP server's address, you may hardcode it into SmtpClient.Host property.
To find out your mail server's address, type nslookup -q=MX example.com at your command prompt.
SMTP is not the best way to report errors, though. Home providers often block traffic on port 25 to all servers but their, to prevent spamming etc.
You better make a web server, create an instance of System.Net.WebClient in your program and send bug reports over HTTP. It's more reliable and you can easily use your client's proxy settings.
You can put the username & password in a web.config/app.config file. You can also encrypt the contents of your .config file (see here).
I do the same sort of thing and when our mail server moves to require authenticated SMTP, we plan to add exceptions for mail from certain addresses so that our automated processes don't need to provide credentials. If you're stuck with authenticated SMTP you'll need to work with your mail service provider to set up the same sort of exception or supply your credentials.
Related
If we have a program that is used to send a mail to store information on a popular mailbox such as gmail, hotmail etc. is it possible without hardcoding the password to send a mail to itself as a logg(a text file basically)??
Since i don't have my own website or host or anything similar, i thought that using a free mailbox to save some sensor logg history to a mail adress would be easy enough.
so the main principle would be basically to send to myself a mail containing the logg and that works great. But is it possible to avoid hardcoding the password into the client? So if i want to send the log to the mail, could we possibly send it to my mail with an unknown source(it's fully okay if it would go to the trash). As it looks now, i have to enter the hardcoded credentials into the program and then send to myself, otherwise it wont get it :(
Yes. You can create your own stmp server and connect it to your own e-mail. If you want to stay anonymous per se, you can use a temp mail.
C# xample can be found here: https://www.c-sharpcorner.com/article/sending-email-with-C-Sharp-using-smtp-servers/
You can, however, use almost any programming language to make an stmp server.
I am trying to send emails using Yahoo or Gmail. Prior to that i want to check if the username and password combination of the email address i am using to send mails is ok and then send the email.
How can i achieve such a thing in Asp.net/C#?
Is there a way to find about the status of the sent email ? (delivered or failed?)
SmtpClient does not offer functions for testing credentials, e.g. just logging in without sending. So the .Net onboard way would be, as previously suggested, to Try/Catch your sending attempt.
If you insist on checking the credentials first, you'd have to implement the SMTP protocol, or parts of it, on your own, using .Net.Sockets.TcpClient. That way you could log on to the SMTP without sending anything.
It is possible to receive a so called NDR (Non-Delivery Report/Receipt), but since that is an email sent back to your designated bounce address, you would have to build an application to read those reports as a background process or similar. There is no guarantee that you will get an NDR.
I don't really see the point of checking username/password prior to sending. You would add error handling anyways, so it either fails or succeeds.
I am developing a site for which I would like to protect buyers by anonymizing their email addresses.Similar to craigslist's system, when a seller needs to contact a buyer they should be able to send an email to an anonymized address such as 1425415125#mysite.com which will then be routed to the user's email address.
My plan right now is to:
Set up a bucket (catch-all) inbox
Generate a random key for each buyer which will be the user specific ('1425415125' above) section of the email address
Monitor the bucket inbox and parse out this user specific section. Once I know the user, the email can be forwarded to the correct address
My questions are as follows:
Can you see any issues with the above solution
Are there any open source solutions to the existing problem
Are there any gotchas that one should be aware of when developing such a system?
Thanks in advance
JP
I did something related, though not quite the same. I setup a catch all inbox on my existing pop3 server (you probably have one already I'm guessing). I then used OpenPop.NET to read all new messages on a timer (say every 30 seconds). In my case I stopped at just processing the messagse but it's easy enough to generate a new message to the appropriate address and copy the body over, then send the new message out on your SMTP server.
One problem I see with your setup, and maybe it's just a misunderstanding on my part, is that while you are protecting the users original email address they will continue to be reachable at 1425415125#mysite.com basically forever. If I understand the way craigslist works, each posting has a different email address, and once the posting has been deleted/removed (or shortly after) the email address stops working. This makes it so that people can't just keep bugging you on that email address. The solution to this issue is easy, just make the email address coorespond to a post id or some other id rather then the users id in the database. The lookup will be just as quick but they will have a new email address each time.
You may wish to look at mail "piping" - the ability for someone to send an email to a mail server, which then gets thrown immediately to an executable, which then forwards your mail onto the recipient (by pulling the real email address from the database based on the incoming address from the piped message).
My personal recommendation would be to check out HMailServer, which has a COM API (the admin side is written in PHP, hence the requirement for legacy interop), is free and open-source, and is very well-documented. It doesn't have mail piping built-in, but is easily extensible given the API and support for scripts which run on server-side message events
HTH,
Benjamin
I think this solution will make sense and is in use in a lot of cases. The hardest part is actually receiving the messages. You can actually handle all of this within your web app if you need to. I wrote a blog post highlighting a couple of ways to receive email in your web app. It applies mainly to Rails but the concepts should be transferable.
The way you are lookimg to do it is the way I created a similar service. I would not recommend you writing your own smtp server. Use an existing mailserver and just use polling or some event based api.
The benefits of using a 3rd party mailserver is you can use existing backup and management tools on it.
Edit: I just noticed this has beed answered here with a better explanation. Pipe incoming email to a script on Windows IIS SMTP?
I do not see any problem with your setup, infact that is correct way to do because if your scheduled application fails, the emails will still be in the catch-all email box. Only once the email has been successfully delivered to somebody, the email should be deleted. You will be able to monitor and log the activity of your own application to monitor progress and failures.
I do not recommend Piping because, if for any reason piping goes successfully but your exe crashes, you will loose the email. Tracking will be difficult. Scheduling the jobs will not be possible.
If your application is independent of mail server, it is easy to manage it and replace your mail server whenever possible. It is easy to extend.
In this you will have to use some pop reader library, and schedule your application to run frequently.
In addition to email, you may consider a pull rather than push delivery mechanism, e.g: a message center web frontend or RSS feed. I say this because deliverability problems to various ISPs can be very difficult to troubleshoot and in my experience your users will never believe it's their ISP.
Can anyone recommend a simple and reliable method of sending email notifications and possibly log files attachments from a C# program without requiring the installer or the user to configure the program by specifying server details and email addresses etc.
(Mainly because they won't know the details, but also because they could change)
The program will normally be run as a service of a Windows Server, but can be run on a client.
I tried connecting to our own mail server and sending a email to myself, but some ISP's are blocking Port 25 on all servers but their own, so that method isn't working reliably.
Tried sending email through gmail but that was less successful as the port they used was blocked by firewalls. Ditto webservices connecting on weird ports.
Trying to use the local smptservice but did not work either.
It would be nice, but not essential if it was not dependant on my own Internet connection/Servers. (Don't mind them being delayed, but prefer them not to get lost).
Are there any webservices on http/https that allow you to do this sort of thing?
TIA
try using cdosys
http://support.microsoft.com/kb/310212
http://www.eggheadcafe.com/articles/20030316.asp
May have discovered the solution.
Was catching up on my blog reading over the weekend and came across a recent entry on Coding Horror and the very first comment mentions PostMarkApp which seems to do everything I need (and almost everything I want, apart from attachments which they are considering).
I have an error message getting returned to me which would appear to be something wrong with the Exchange set up. Is there a possibility that I'm doing something wrong? I have no idea where to to start to track this down:
The following recipient(s) cannot be reached:
Customer Service Account on 6/3/2009 11:00 AM
There was a SMTP communication problem with the
recipient's email server. Please
contact your system administrator.
<fgdc.myservername.net #5.5.0 smtp;550 Requested action not taken: mailbox unavailable>
This is perhaps a ServerFault question, but I wanted to get some input as to whether it's even possible that there's something I can do to fix it in my code.
Site is Asp.Net C#, using URL Routing
Server is 2003, 64-bit and running Exchange 2003
UPDATE
Turns out it was a layer of Spam protection. Figured out this was only happening for internal addresses and MIMESweeper looks to be throwing away the messages. They were coming from an external web server, but sending with an internal domain. Flags go up. Messages don't go.
My guess is that you have the wrong user specified. Particular versions of Exchange are very picky about usersnames/emails. If you put just the "full name" in as the recipient, you won't get anything. You have to have an exact Match AND with Exchange 2000 you also needed an X.400 address to have it work too.
There are so many things that can go wrong with the Exchange SMTP gateway that I really can't say what exactly your problem is. You're better off talking with the Mail admin, and turning on Message Tracking for that mailbox to find out what is going on under the hood.
There is nothing to fix - the only thing you can do is recover gracefully and log the error. The only thing to check is make sure you have the correct email address since the error is "mailbox unavailable".