views:

53

answers:

3

We are developing a .Net Windows application in C# for commercial distribution.

Objective

I want to add a function to allow the user to email a file to any email recipient from within the application without needing an email client on their PC, just an internet connection. The email they send needs to appear that it has come from them (i.e. their email address is in the FROM/REPLYTO field) so that the recipient can identify where the email has come from and they can reply to it.

Current Approach

I was intending to use the MailMessage class in System.Net.Mail, but it requires an SMTP server to send the email. The problem with that is, i dont want the user to have to configure anything to send emails from our application - i want it set up by us. In other words, i want to define what SMTP server to send the email from and hardcode it in the application.

I have tried to use Gmail as the SMTP server, however one major drawback - Gmail automatically rewrites the "From" line of any e-mail you send via their SMTP gateway to your Gmail address, so when we tested this, even though in the MailMessage code we set the FROM property to [email protected], when the email was received, the From field displayed [email protected]

Questions

  1. If this software application is going to be distributed to many users in different network environments, is this method the best to use? If so, is there a free/public SMTP server i can use for our application to achieve this that will allow the end-user to define the FROM and REPLYTO fields?

  2. I have been told that not all ISPs / organisations will permit arbitrary SMTP connections and/or if the sender implements an SPF record the message may be rejected. Does that mean my intended approach may not always work?

  3. Is there any other common or more stable method i could use to achieve my original objective?

+1  A: 

I don't think you can guarantee any smtp server will always be available. e.g. gmail's smtp is blocked at my office.

You're probably better off creating a web service that they send the attachment to and then you route it through your mail server.

Conrad Frix
Hi Conrad, thanks for your reply.Would a webservice you suggest be more stable and have a less chance of getting blocked? Is there anything i should be aware of in developing such a webservice, for example, any possible blocks?
+1  A: 

1) I'd be surprised if you found a public SMTP server to do this as it would just be used heavily as a spam relay.

2) A lot of residential ISPs do block SMTP traffic from leaving their network. However, they are doing this by blocking port 25 so if you host your own SMTP server on an alternate port it won't get blocked except in the most extreme cases.

3) see below

I see two items you have to address:

Getting the message from the sender to you
Conrad's suggestion of using a web service is a good one as it gives you more control over the transport of the message to you. You can implement whatever authentication you deem necessary to make sure the person sending the message is legit. You could use SMTP to send the messages through a mail server hosted by you, but would need to focus on knowing who to safely allow to send and who not to so you don't end up as a spam relay.

Sending the message from you to the recipient
You can still send the message to the final recipient via SMTP to their mail host. I would suggest sending the email with the from as your application (ex: [email protected]) and define the reply-to address for your original sender. If you try using their address in the from, you will get more spam rejections.

If I understood your description, the messages will only be being sent to other users of the application?
If so, you could take the web service route on both parts of the communication. Sender delivers the message to your centralized server over a web service call, when the recipient user opens the software, it checks with your server to see if there are any messages waiting for them.

EDIT:
Yes, the part on the destination emails, I could read it both ways, guess I leaned toward the wrong one.

You will have to deliver the messages in the end via smtp, I still suggest using your own from and put the sender in the reply-to unless these are corporate customers that you can get to add your smtp server to their SPF records.

Also, investigate specific major mail targets like Yahoo! and GMail for how to interact with them such as: http://mail.google.com/support/bin/answer.py?hl=en&answer=81126
http://help.yahoo.com/l/us/yahoo/mail/postmaster/postmaster-15.html
http://help.yahoo.com/l/us/yahoo/mail/postmaster/bulkv2.html

ManiacZX
Hi ManiacZXThanks for your reply. Just a few comments1) I implemented Hotmail's SMTP in our code, and initial tests seems like it works ok. However, i assume it may get blocked for various reasons if it is run from other networks by the end-user of our software.2) Hotmail SMTP uses port 25, but also port 587 with TLS orSSL Encryption if 25 is blocked.
3) You may have misunderstood my original description. Our windows application is a financial software tool. Just like many other software tools, it creates a data file (just like xls for Excel and doc for Word). I want to add a function in our software to allow the user to send the file to any email recipient. This is similar to the "File > Send To > Mail Recipient (as Attachment)" option in Microsoft Office, however, instead of launching their default mail client in Windows, and sending it through that, i want to ask the user for an email address and then we send the file programmaticly.
If hotmail is letting you set the from to whomever you want, I'd be cautious in using that in a released application as I doubt it is an intended feature and so could change at any time.
ManiacZX
A: 

I've used something similar to this to send email without having to rely on smtp. YMMV

JohnForDummies