0

I am working on an application that, among other applications, allows users to send emails. It works by writing everything onto an SQL server, so you can have multiple instances of an application.

The email sending currently works with an "Outbox" table on the SQL server, to which application instances directly write the data with SQL statements. I have, however, hit an issue, that a requirement for attachments on the emails has arisen.

My thinking is that if I can send the attached files to a directory on which the SQL server resides (possibly the TEMP directory?), and then store the path to that file (or a UUID, if the file is constant) in the table. The issue is I have no idea particularly where to start with sending the file, as I am still vaguely new to C++.

One term I have come across is sending it with sockets, but am struggling with where to start with it and do not know if it is indeed the best option. Could anyone provide some advice on this matter?

Thanks in advance.

Raiden616
  • 1,545
  • 3
  • 18
  • 42

1 Answers1

1

If I correctly understand the way it works (applications save the emails to SQL then another application takes them out and sends them) you have two choices:

  1. Save the attachment as binary in the SQL and have the mailer application do the rest.
  2. Use sockets to transfer the file to the SQL server and save the path to it just as you said.

I'd say option 1 would be the best option if I understood correctly the way its currently working. And as for option 2, there are probably other ways to transfer the file but sockets would be the easily cross-platform option.

Its not hard to get started with sockets, there are a lot of examples all over the internet.

Community
  • 1
  • 1
Edward A
  • 2,291
  • 2
  • 18
  • 31
  • Thanks for the advice - could you recommend a guide for doing this with C++ and ADO? I am currently accessing my sql database that way. My biggest question is - could you expand on "do the rest" ^__^ ? – Raiden616 Feb 12 '14 at 11:12
  • @user1014679 I'm not familiar with neither ADO or with the mail transfer protocol in general, but what I meant is that application 1 (user app) should take the path to the file the user wants to attach, read it as binary, save in the SQL along with the text and other information. Then application 2 (server app) should read the data from SQL and send the mail. You'll want to look up how the attachment part of the mail should look like, perhaps [this](http://stackoverflow.com/q/17097806/1312672) and [this](http://en.wikipedia.org/wiki/MIME) might help. – Edward A Feb 12 '14 at 19:19
  • Yep I understood :) I have a mail wrapper that can take file location strings as a parameter to add attachments, so that's that taken care of. So if I wanted to go the BLOB route, I can see the server application having to: read the binary; reconstruct the original file in a local, temporary location; and then add that location string to my mail wrapper. Do you know how this would be done? – Raiden616 Feb 13 '14 at 13:28
  • @user1014679 You'll have to look into [fstream](http://en.cppreference.com/w/cpp/io/basic_fstream) and the [MYSQL connector](http://dev.mysql.com/downloads/connector/cpp/). – Edward A Feb 13 '14 at 18:01