I would like to create a mail sender on C++ (not Mail Client for eg. GMail). In this mailer I want to be able to change the headers also.
I have already downloaded and installed the POCO libraries, that might help (I found it on a similar anwser).
For example, what I would like is a command like below:
e-mailsend(to,headers,subject,message);
// Or something like:
email.send(to,headers,subject,message);
However, If possible, I would like to use a C++ Mail function not a system function (like mail-utils in unix).
If you need any more explanation please comment...
In your comments you asked for an option without an SMTP server.
SMTP requires an SMTP Server. The choice is that could send emails directly (e.g. to joe at yahoo.com on port 25) or to a SMTP server that will relay the message.
Ideally, you will want your own SMTP server locally (so your application is simpler and your SMTP server sends the messages in the background, handles retries, bounces and connection errors) and use a reputable SMTP service or an existing email account.
If you want to send spam, I'd strongly advise against it.
If you want to send a small number of messages that will be opened by people expecting those messages, use a normal account (Yahoo, GMail, Google Apps, etc) and if you find your application not responsive enough, install Postfix, Sendmail or whatever local SMTP server you like.
If you want to send a large volume of emails and you are sure those message won't get you targeted as a spammer, use an SMTP service, like SendGrid (note: they also have a web API that you might find easier to use than SMTP).
Depending on which of the above you need, I'm sure answering your original question with a recommendation for SMTP C++ clients (like POCO) with become simpler.
Related
I want to send email over SMTP using c++ code, how should I handle it in generic way that a random user don't have to handle SMTP server specification? (Windows)
Without specification means user should not have to write IP address of SMTP server etc.
Install an smtp relay server on the same host where the code runs and set the SMTP server in the code to 'localhost'.
Jasper's answer is correct. You need to install an SMTP server on the host that your C++ program is running on. One option is qmail. See www.lifewithqmail.org for more info, including a step-by-step guide on how to install it.
Most linux SMTP servers (including qmail) will create a smylink /usr/sbin/sendmail which you can use to send an outgoing message. In general, the syntax is:
/usr/sbin/sendmail recipient#domain.tld < /path/to/file/containing/the/message
See the help file for more info, including flags that you can use to specify the envelope sender, etc.
You can send a message from your C++ program by doing a system call to /usr/sbin/sendmail similar to the above.
You could use Simple MAPI, but you need an email program supporting the MAPI-interface like Outlook.
I have seen many tutorials (http://curl.haxx.se/libcurl/c/smtp-multi.html, VMIME website, etc) that explain how to send mail through some server like GMail or whatever. That is, they require a username/password to log in to some server, and then they forward the email through the server to the destination.
What I am looking for and cannot find is an explanation of how to send email that is not routed through a server though. How do you send email without a mail server? I am looking for a [Linux] library that can let my program be the mail server itself, both to send mail and receive it. If this is not possible with curl or vmime then I will be glad to switch to another library. I really do not want to have to roll my own SMTP server, but I've spent a day on google to no avail, and read the VMIME book but I can't find anything helpful and it's a little abstruse to my mind.
Edit:
So basically I'm looking for a SMTP server library (that can also send emails to other servers) for C or C++. Does such a thing exist? I see them for .NET and Java and Python but no C or C++ yet. Still googling...
Sadly, I don't know of any that are still active. VMIME has some support but the API for SMTP/SMTPS is kinda awkward looking. I have looked at libcurl for the sending portion too. It looks a bit easier to manage than VMIME's SMTP/SMTPS API. I am currently using VMIME to generate the messages and am sending using the MSMTP utility. The combination of VMIME and MSMTP works great but would prefer to keep it all in one utility program...
An app is designed to be installed on a user's computer, hence, an email function from the app would very much depends on the user's ISP service. Port 25 may be open or may be blocked.
When I use standard code for mail ua including port 25, it seems to deliver the email, however, for some user whose ISP blocks port 25 email does not go through. I'd like to have a reliable way to determine if port 25 fails to deliver email Instantly and then try to use another port to send email. In other words, I'd like to leverage two ports, if port X fails then automatically switch to port Y. Doable?
Btw, the web server side scripting language I'm using is Adobe ColdFusion's sibling, Railo, and the specific tag is CFMAIL. As mentioned above, wrapping CFTRY around CFMAIL does not help for this purpose.
Thanks.
There are multiple factors in determining if your message gets delivered.
1) When you send your message with CFMAIL, you can either specify a mail server in the cfmail tag, or use the server default. When the tag is executed, coldfusion/railo will try to access that server. If the server is unavailable or blocked, your message will go to the coldfusion/railo undeliverable folder. The only way to check that is to write a script to monitor the undeliverable folder and its content.
2) IF coldfusion/railo successfully connect to the SMTP server and attempts to hand off the email, your notifications would come from the SMTP server rather than coldfusion/railo. The message would be sent from the SMTP server to the failto="" path, or the from="" if not specified. That email would be notified for "mailbox does not exist", "relay not allowed", "user over their mailbox limit", etc....
If you need to monitor those bounces, you could create a separate email account for the failto="" and use CFPOP to monitor the email account for bounces.
Also, if you use a company like sendgrid for your outgoing SMTP server, they will provide an API to monitor bounces, opt outs, spam complaints, etc...
I'm developing a cross-platform C++11 application and I need to send a validation email to a user-entered address to make sure his email account exists and is valid.
I know there are temporary mail services like mailinator, but honestly I feel like a validation email is a good approach in my case since it gives people malicious intention more work to do to circumvent the system and also goes well with the rest of the application (example: having the email address allow me to automatically send status updates to users).
I have searched on the internet but I haven't been able to find a portable, cross-platform way to achieve this, at least without introducing big dependencies.
How can this issue be solved?
This email better not send from the client side. Write a server side http api and accept request from the client side application, then send the email on server.
Given that we don't even have networking(!) in the C++11 standard (not to mention the POP3, SMTP or the IMAP protocols on the top of it), I am afraid you cannot do it without "introducing big dependencies."
If you are willing to use third party libraries
VMime
libcurl
SmtpClient for Qt
implementint the protocols yourself on the top of boost::asio
are viable options depending on your needs and licensing requirements.
I don't have too much experience programming in C++, but I need to build a basic application for sending state emails from a computer using windows or linux, and I've found that POCO C++ suppoorts both platforms, but I have a proxy http provider behind to filter unauthorized connections, so, how could I do it?.
You can't send SMTP e-mail through a HTTP proxy.
But you can make a HTTP connection to a website you control. And you can write a web-to-email script and put that on your website. E.g. your script can take a status message as a POST parameter and then send it out as e-mail.
Spammers often try to hack web-to-email scripts to send spam, so please make sure your script has a hard-coded destination e-mail address. That way the spammer can only send mail to you, not everyone else on the Internet. Whatever you do, don't pass the destination e-mail address as a parameter.
regarding web to email scripts - make sure you strip newlines from anything that ends up in email headers! (to prevent spammers from injecting headers)