Send email from gmail using Telnet - email

I am working on windows and I have enabled telnet client
In cmd prompt:
$telnet smtp.gmail.com 587
220 mx.google.com ESMTP dk3sm50678627pbc.32 - gsmtp
$Helo
250 mx.google.com at your service
$ mail from: <myuser#gmail.com>
530 5.7.0 Must issue a STARTTLS command first. dk3sm50678627pbc.32 - gsmtp
$ STARTTLS
220 2.0.0 Ready to start TLS
$ mail from:
C:\Users\{myuser}>
Connection to host lost.
Don't know What is the problem ?
Can anyone help me out , how i can send emails from gmail server using telnet from command line >

smtp.gmail.com requires TLS. The basic telnet client that comes with windows does not know how to negotiate TLS with a server. You may want to use openssl instead, which is able to negotiate TLS. See http://www.madboa.com/geek/openssl/#cs-smtp for an example of how to do this.

The gmail smtp must use smtp auth before you sending your email. The smtp auth need username and password.
see this link blow if you can read in Chinese.
http://linxucn.blog.51cto.com/1360306/837365
Last I sugguest you use java to ask gmail smtp server to send email, It will be more easy , becasue you needn't encode the smtp auth to BASE64 or anything else.
GOGOGO, good luck :)

Put into a VBS file, ie sendmail.vbs.
Set emailObj = CreateObject("CDO.Message")
emailObj.From = "cat#gmail.com"
emailObj.To = "cat#gmail.com"
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
emailObj.AddAttachment "c:\windows\win.ini"
Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "cat"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Ccat1"
emailConfig.Fields.Update
emailObj.Send
If err.number = 0 then Msgbox "Done"
At Google's web site for GMail you have to turn this feature on for CDO to work.
At your Gmail page click Settings - Accounts and Import - Other Google Account Settings - [At very bottom of page] Allow less secure apps.
Also from memory you also have to click a link in an email the first time you use it (it's been a few years).

Related

Sending Sparkpost smtp Email using c#

I have looked at numerous answers in stack overflow and other places and I still cannot find a good example on how to:
in C#, Successfully send email via sparkpost smtp after STARTTLS was introduced. Documentation in Sparkpost (https://www.sparkpost.com/docs/getting-started/getting-started-sparkpost/, search for starttls) refers to the following settings:
SMTP host: smtp.sparkpostmail.com
Port: 587 or 2525
Encryption: STARTTLS
Username: SMTP_Injection
Password:
In my current applications, in web.config, I configure sparkpost smtp like so:
<network host="smtp.sparkpostmail.com" port="587" userName="SMTP_Injection" password="..." enableSsl="true" />
…
This worked fine until the start of july. And then TLS 1.0 was no longer supported. So I would like to get our email working again
But how does STARTTLS come into play ?
I added the ServicePointManager.SecurityProtocol line to my smtp C# code and it all started working again. Hope this helps.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.sparkpostmail.com";
smtp.Port = 587; // 2525
smtp.EnableSsl = true;
//NOTE THE LINE BELOW
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
smtp.Credentials = new NetworkCredential("SMTP_Injection", "YOURKEY");

PHPMailer not able to send send email with ec2

I'm using PHPmailer to send account verification mail, I'm using AWS ec2 instance, however, that mailer is working fine in localhost but when I upload that to server emails are not going,
at first, i used SendGrid credentials to send emails, failed, then tried Gmail SMTP, failed, and somewhere I read that ec2 can't send emails, then I created SES also, still can't able to send.
searched on the web abt that but no answers are fixing my problem,
in localhost, in can send emails with the same code and with SendGrid of Gmail credentials, why I can't send with the server?
my PHP mailer code is:
$sub = "Thankyou For registration! Confirm Your mail to Login";
$mailBody = "<h1>You are successfully registered<br />Visit site to login</h1>";
require 'mailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = "tls://email-smtp.us-east-1.amazonaws.com"; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = "smtp_username"; // SMTP username
$mail->Password = "smtp_password"; // SMTP password
// $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom("my_mail_id#gmail.com", "SMTP_REPLAY_NAME");
$mail->addReplyTo("my_mail_id#gmail.com", "SMTP_REPLAY_NAME");
$mail->addAddress("recipient_mail_id#gmail.com"); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $sub;
$mail->Body = $mailBody;
if(!$mail->send()) {
echo 'Message could not be sent.';
} else {
echo 'Message has been sent';
}
it shows Message has been sent but I cant receive emails, checked in spam folder also, no clue of mail!
even I have openSSL certificate also! opened SMTP port for both inbound and outbound in security group of ec2, everything working fine but PHPMailer!
Get your protocols straight. In the Host you're specifying tls, but telling it to connect to Port = 465, which will not work with TLS. Either change your Port to 587 (preferred) or change your encryption method to ssl. Enabling debug output (SMTPDebug = 2) will let you in on what's happening in the conversation with the server.
A perusal of the troubleshooting guide would probably help.

PHPMailer Update Issue (from 5.2.9 to 5.2.16)

PHPMailer works great, I've been using it for ages and it's pretty good. I have had version 5.2.9 on my server and have got the newer, 5.2.16 uploaded,
Now my sites have issues of:
"SMTP Error: SMTP connect() failed."
I have added $mail->SMTPDebug = 4; and it gives me this:
2016-11-15 17:18:10 Connection: opening to localhost:25, timeout=300, options=array (
)
2016-11-15 17:18:10 Connection: opened
...
removed excess repetative lines
...
2016-11-15 17:18:10 SERVER -> CLIENT: 250-mail.servernetwork.co.uk Hello www.domain.co.uk [::1]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2016-11-15 17:18:10 CLIENT -> SERVER: STARTTLS
2016-11-15 17:18:10 SMTP -> get_lines(): $data is ""
2016-11-15 17:18:10 SMTP -> get_lines(): $str is "220 TLS go ahead
"
2016-11-15 17:18:10 SERVER -> CLIENT: 220 TLS go ahead
2016-11-15 17:18:10 SMTP Error: Could not connect to SMTP host.
2016-11-15 17:18:10 CLIENT -> SERVER: QUIT
2016-11-15 17:18:10 SMTP -> get_lines(): $data is ""
Nothing else has changed on the server. Reverting to PHPMailer Version 5.2.9 removes this error (and emails are sent ok).
I have also tried to update from 5.2.9 to 5.2.14 and 5.2.13 and the same error occurs. I have made no changes to the DNS and there are no DKIM or other identifiers set in the PHPmailer classes to allow version 5.2.9 but not 5.2.13 or 5.2.16 ones.
I'm using PHP Version 5.6.2.
Any clues as to why this is so?
The sending code:
(I realise the code is not the best but it's an older site I picked at random to test out PHPMailer 5.2.16)
$mail = new PHPMailer();
//$mail->SMTPDebug=4;
$mail->Host = "localhost";
$mail->WordWrap = 78;
$mail->isSMTP();
$mail->From = $fromMail;
$mail->FromName = "Website: ".$name;
$mail->AddAddress($toEmail);
$mail->Subject = $member['bizname'] . " Enquiry";
$mail->Body = $message;
if (!$mail->Send()) {
...
}
The proper way to initialize the settings is, note that you should set the $mail->SMTPAuth = true:
<?php
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com'; // Specify main SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
//Only if you have SSL/TLS on your server
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
...
After spending a day or so asking various related questions, I found the answer lies with an update applied in PHPMailer 5.2.10.
I found that while my server is TLS certified, there seems to be a problem with using a localhost Host; possibly that PHPMailer may be trying to check the certificate applies to localhost domain, which of course it doesn't.
I found a solution to sending mail via Localhost now is therefore to disable auto-TLS with the following:
$mail->SMTPAutoTLS = false;
Using this all emails now send correctly.
NOTE
As Bodi0 stated using SMTPAuth is best practise, however I didn't realise that it is unnessecary for localhost mail servers as the authenticaton is implicit.
Comments on this answer to a related question about ->SMTPSecure settings gives more details.

SMTP authentication failure while using SendGrid/Gmail

I am getting SMTP Authentication Failure on the server and the mail is getting send via the server SMTP only...
It appears to be a server configuration or related problem, but I am not sure.
This is the debug details:
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
Failed to authenticate password. Error: 535 Incorrect authentication data
from: 250 OK
to: 250 Accepted
data: 354 Enter message, ending with "." on a line by itself
250 OK id=1U8Pjp-0002As-FB
quit: 221 ************** closing connection
Your message has been successfully sent using the following protocol: smtp
While testing from my local system, this works and the email is being sent via sendgrid.me
Again, This may not be a SendGrid Problem, but if you have faced similar issue, Can you please tell me what is the problem here?
I am using CentOs and I have cPanel in the server. I believe we are using EXIM for mail server.
For anyone that comes across this in future and are using cpanel/whm, you need to 'disable' this option under 'SMTP Restrictions' in WHM.
I was able to resolve this.
The issue was my server was not allowing the use of external SMTP and using its own SMTP server. I changed the settings and now it works fine.
I am using centos 7 Finally it works!
I was getting this issue(tail -f /var/log/mailog):
to=<usmanali#example.com>, relay=smtp.sendgrid.net[169.45.113.201]:587, delay=0.3, delays=0.05/0.07/0.16/0.02, dsn=5.0.0, status=bounced (host smtp.sendgrid.net[169.45.113.201] said: 550 Unauthenticated senders not allowed (in reply to MAIL FROM command))
Then i changed file /etc/postfix/main.cf in this way that added following lines into end of file
mtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination
mailbox_size_limit = 256000000
# Sendgrid Settings
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:apikey:SG.YOUR_SENDGRID_KEY
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = may
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
Then Installing postfix missing module dependency using:
sudo yum install cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain
Then restarting postfix
sudo systemctl restart postfix.service

Gmail smtp SASL authentication

I'm using postfix to send email via gmail with an application's password (two step-validation activated).
Each time I test sending mail using sendmail command, I get this error:
Action: delayed
Status: 4.7.14
Diagnostic-Code: X-Postfix; delivery temporarily suspended: SASL authentication
failed; server smtp.gmail.com said: 534-5.7.14
<https://accounts.google.com/signin/continue?...> Please log in via your web browser and?534-5.7.14 then try again.?534-5.7.14
This is my postfix configuration:
main.cf
myorigin = /etc/mailname
mydestination = mydomain.com, localhost.fr, localhost
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
/etc/postfix/sasl/sasl_passwd:
[smtp.gmail.com]:587 admin#mydomain.com:application_password
And this is how I used sendmail:
sendmail -v ...
From: admin#mydomain.com
Subject: Test
This is a test mail
.
Any ideas ? Thanks !
For anyone finding this who has run into the same scenario:
Using an app specific password
2FA enabled on your account
Seeing 'delivery temporarily suspended: SASL authentication failed; server smtp.gmail.com[173.194.68.109] said: 534-5.7.9 Please log in with your web browser and then try again' in your log
You may need to visit https://accounts.google.com/DisplayUnlockCaptcha to 'bypass' the captcha, which will enable the account access and get everything working.
Allow less secure apps: If you don't use 2-Step Verification, you might need to allow less secure apps to access your account.