R
R
Ribachok2021-09-21 22:11:09
Email
Ribachok, 2021-09-21 22:11:09

How to send a file by mail?

There is a file file.txt, I would like to send it to my gmail mail. How can this be done, preferably using pure c++ tools, without libraries?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
Wataru, 2021-09-21
@wataru

preferably using only bare c++ tools, without libraries?

If you're on Linux, type "man sendmail" in a terminal. Understand the command and call it from a C++ program via system.
Otherwise - deal with sockets, SMTP, TCP protocols. You can write a simple client of lines for 3000 in a couple of months, probably. Well, or, after all, revise your conditions and use libraries or a more convenient language for this. So in python, this is done literally in 2 lines.

C
CityCat4, 2021-09-22
@CityCat4

If, according to the conditions of the task, the use of external commands is permissible, then first man mail,then working out sending the file through the command mail, then calling it all through system()or exec()..
If you need to specify from whom - instead mailuse sendmail.
If the use of external commands is unacceptable and you need / want to do it purely by means of the language (this is of course stupid, but informatively green) - we take RFC822, study the format of the e-mail message, then we take it and implement it.
That is, you will need to:
- form the correct headers of the letter
- form an attachment (mime-encoded, do not forget that onlydisplayed ASCII, no special characters!)
- connect to the server, transfer the initial information (who you are, from whom, to whom)
- do not forget about SPF / DKIM / DMARC (otherwise, with a high degree of probability, the letter will be in the trash, if at all it will be accepted - gmyl in this respect, simple as a log)
- to convey the formed letter
Wataru correctly said - a couple of months of hard work will go away, but how many skills you will immediately pull up: D
On the bash, by the way, one line is done (if without changing From :) and two or three - if with a change.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question