How would you implement database updates via email

2020-05-24 16:51发布

I'm building a public website which has its own domain name with pop/smtp mail services. I'm considering giving users the option to update their data via email - something similar to the functionality found in Flickr or Blogger where you email posts to a special email address. The email data is then processed and stored in the underlying database for the website.

I'm using ASP.NET and SQL Server and using a shared hosting service. Any ideas how one would implement this, or if it's even possible using shared hosting?

Thanks

6条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-05-24 17:05

E-mails can be trivially forged. I would only do this if you can process PGP / SMime certificates in your application.

Other than that, I see no reason why not!

查看更多
甜甜的少女心
3楼-- · 2020-05-24 17:08

use a dotnet popclient to read the incoming emails, parse them for whatever you are expecting and insert the data into the database.

see codeproject website for simple popclient implementation you would have to decided on the email content yourself, eg data only, payload of sql statements, etc

查看更多
SAY GOODBYE
4楼-- · 2020-05-24 17:17

You could also identify the user based on sender address. This is how Tripit (and probably others) does it. This only requires one e-mail address on your end.

查看更多
在下西门庆
5楼-- · 2020-05-24 17:18

If the data is somewhat "critical", or at least moderately important, do NOT use their username as the "change-data-address". Example: You might be tempted to create an address like username@domain.com, but instead use username-randomnumer@domain.com where you give them the random number if the visit the web-page. That way people can not update other peoples data just by knowing their username.

查看更多
▲ chillily
6楼-- · 2020-05-24 17:19

I have done something similar, using Lumisoft's IMAP client and scheduling a task in my app that checks every x minutes the configured mail address for updates. For scheduling I recommend quartz.net. No launching external processes or anything.

查看更多
爷的心禁止访问
7楼-- · 2020-05-24 17:20

For starters you need to have hosting that allows you to create a catch-all mailbox.

Secondly you need a good POP3 or IMAP library, which is not included AFAIK in the .NET stack.

Then you would write a Command Line application or a Service that regularly checks the mailbox, pulls messages, inserts content in db based on the "To" address (which is unique for each user), and then deletes the email from the mailbox.

It's feasible and sounds like fun. Just make sure you have all you need before you start!

查看更多
登录 后发表回答