By using SMTPjs you giving you credential to SMTPjs by using the secure token or not. They need the credential to send a email for you, so there is no way to create the token yourself. A secure way to do it is by using a service that use OAuth (or creating your own server to send mail, of course).
To send an email in Node. js, use the nodemailer module. The nodemailer is a module that gives you the ability to send emails without hassle easily. It uses a Simple Mail Transfer Protocol (SMTP), a protocol for sending email messages between servers.
The jQuery AJAX function will call a Web Service (Web Method) which will send email using Gmail SMTP Mail Server. Once the Email is sent, a Confirmation will be sent back to the jQuery AJAX function which in turn will be display a Success message using JavaScript Alert Message Box.
The way I'm doing it now is basically like this:
The HTML:
<textarea id="myText">
Lorem ipsum...
</textarea>
<button onclick="sendMail(); return false">Send</button>
The Javascript:
function sendMail() {
var link = "mailto:[email protected]"
+ "[email protected]"
+ "&subject=" + encodeURIComponent("This is my subject")
+ "&body=" + encodeURIComponent(document.getElementById('myText').value)
;
window.location.href = link;
}
This, surprisingly, works rather well. The only problem is that if the body is particularly long (somewhere over 2000 characters), then it just opens a new email but there's no information in it. I suspect that it'd be to do with the maximum length of the URL being exceeded.
Here's the way doing it using jQuery and an "element" to click on :
$('#element').click(function(){
$(location).attr('href', 'mailto:?subject='
+ encodeURIComponent("This is my subject")
+ "&body="
+ encodeURIComponent("This is my body")
);
});
Then, you can get your contents either by feeding it from input fields (ie. using $('#input1').val()
or by a server side script with $.get('...')
. Have fun
You don't need any javascript, you just need your href to be coded like this:
<a href="mailto:[email protected]">email me here!</a>
You can use this free service: https://www.smtpjs.com
<script src="https://smtpjs.com/v2/smtp.js"></script>
Email.send(
"[email protected]",
"[email protected]",
"This is a subject",
"this is the body",
"smtp.yourisp.com",
"username",
"password"
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With