Introduction
This article explains how to write code to send an email using a personal computer without an SMTP server. Even if your server only allows one email per day, it's still possible.
Prerequisites
To follow this guide, you'll need a personal computer and basic understanding of programming languages such as Python, Node.js, or Ruby.
Code Blocks
Python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
msg = MIMEMultipart()
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
msg['Subject'] = 'Test Email'
body = 'This is a test email sent from my personal computer.'
msg.attach(MIMEText(body, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('[email protected]', 'your_password')
text = msg.as_string()
server.sendmail('[email protected]', '[email protected]', text)
server.quit()
Node.js
const nodemailer = require('nodemailer');
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: '[email protected]',
pass: 'your_password'
}
});
let mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'Test Email',
text: 'This is a test email sent from my personal computer.'
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
Ruby
require 'mail'
mail = Mail.new do
from '[email protected]'
to '[email protected]'
subject 'Test Email'
body 'This is a test email sent from my personal computer.'
end
mail.deliver!(:smtp => {
:address => 'smtp.gmail.com',
:port => 587,
:user_name => '[email protected]',
:password => 'your_password',
:authentication => 'plain',
:enable_starttls_auto => true
})
- Book: "Learning Python, 5th Edition" by Mark Lutz
- Article: Node.js Email Module
- Online Resource: Ruby MIME Library