CDO HELO strips special charcters resulting in relay denied - email

I have C++ code that utilizes CDO to send email based upon triggering events. I've included portions of the code below. The problem is that when app run on a server with embedded dashes such as SERVER-ABC-123 some mail servers at customer sites will reject the request with a 550 error for relayed denied. The HELO packet contains the server name with the dashes stripped which I think is the root cause of the problem.
Is there anyway to force CDO to include the FQDN?
Here is SMTP trace info
Client => Server: HELO SMCABUTELC03\x0d\x0a
Server => Client: 250 int2.unimax.pvt Hello sm-cabu-telc03.swna.wdpr.unimax.com [192.168.24.25], pleased to meet you\x0d\x0a
Client => Server: MAIL FROM: \x0d\x0a
Server => Client: 550 5.7.1 ... Relaying denied. MAIL FROM: corp.2n.admin#sm-cabu-telc03.swna.wdpr.unimax.com does not end with SMCABUTELC03\x0d\x0a
CDO::IMessage* cdoMessage = NULL;
CDO::IConfiguration* cdoConfiguration = NULL;
cdoConfiguration->get_Fields(&cdoFields);
cdoFields->get_Item( _variant_t( cdoSendUsingMethod), &cdoField1);
cdoField1->put_Value( _variant_t( (long) CDO::cdoSendUsingPort));
cdoField1->Release();
cdoField1 = NULL;
cdoFields->get_Item( _variant_t( cdoSMTPServer), &cdoField2);
cdoField2->put_Value( _variant_t( emailHostName.gets()));
cdoField2->Release();
cdoField2 = NULL;
cdoFields->get_Item( _variant_t( cdoSMTPServerPort), &cdoField3);
cdoField3->put_Value( _variant_t( emailHostPort));
cdoField3->Release();
cdoField3 = NULL;
cdoFields->get_Item( _variant_t( cdoSMTPAuthenticate), &cdoField4);
if ( emailUserName.size() == 0 )
{
cdoField4->put_Value( _variant_t( (long) CDO::cdoAnonymous));
}
else
{
cdoField4->put_Value( _variant_t( (long) CDO::cdoBasic));
}
cdoField4->Release();
cdoField4 = NULL;

Related

Xamarin, get error sending mail using SmtpClient

I am using System.Net.Mail.SmtpClient to send mail in my Xamarin Form app. It's set to using my gmail address, and working great.
I would like to get the error from the smtp server (if there is one) to inform the user.
So, I am using the event _SendCompleted
Here my code
(sending email)
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(outils.emailEmetteur);
mail.To.Add("toto#outlook.frfr");//Tiers.contactEmail);
mail.Subject = outils.emailObjetDefaut;
mail.Body = outils.emailMessageDefaut;
bool fileExist = File.Exists(filePath);
if (fileExist)
{
Attachment pJ = new Attachment(filePath);
mail.Attachments.Add(pJ);
smtpServer.Port = 587;
smtpServer.Host = "smtp.gmail.com";
smtpServer.EnableSsl = true;
smtpServer.UseDefaultCredentials = false;
smtpServer.Credentials = new NetworkCredential(outils.emailEmetteur, outils.emailEmetteurMDP);
try
{
smtpServer.SendAsync(mail, null);
smtpServer.SendCompleted += smtpServer_SendCompleted;
return true;
}
catch (Exception ex)
{
}
}
(send completed event)
private static void smtpServer_SendCompleted(object sender, AsyncCompletedEventArgs e)
{
string token = (string)e.UserState;
string info = "";
if (e.Cancelled)
{
info = "Send canceled.";
}
if (e.Error != null)
{
info = e.Error.ToString();
}
else
{
info = "Message sent.";
}
}
I am trying to send an email to an incorrect address (toto#outlook.frfr)
My event is correctly triggered, but e.Cancelled and e.Error are NULL, and, in my Gmail inbox, I receive an error from smtp server telling me that the email address was incorrect, and that what I want to get in my Xamarin app.
Do you have any idea ? Thanks :)
Your client relays it to Gmail's outgoing mail server; the transaction to submit the message to SMTP is successful. The error only happens later, when Gmail tries to connect to the recipient's mail server, and can't resolve it; at that point, your client is no longer necessarily connected, and so the mail server generates a bounce message and delivers it to the sender's inbox.
In the general case, you either have to write your own mail server (but no, don't go there) or examine the inbox for bounce messages.

phpmailer 6.0 success message but no mail received using gmail as relay

I've tried a bunch of alterations to my code but with no effect. The code itself does not return any errors but instead gives a success message. I am using gmail as my relay.
P.S, I commented out $mail->IsSMTP(); because I saw a similar question here that used it as a fix, I was getting an "smtp failed to connect" error.
I am using PHPmailer 6.0.
Here is my code:
<?php
require_once('vendor/autoload.php');
define('GUSER', 'example#gmail.com'); // GMail username
define('GPWD', '*********'); // GMail password
function smtpmailer($to, $from, $from_name, $subject, $body) {
global $error;
$mail = new PHPMailer\PHPMailer\PHPMailer(true); // create a new object
//$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, $from_name);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
smtpmailer('to#mail.com', 'from#mail.com', 'yourName', 'test mail message', 'Hello World!');
if (smtpmailer('to#mail.com', 'from#mail.com', 'yourName', 'test mail message', 'Hello World!')) {
// do something
}
if (!empty($error)) echo $error;
?>
If I uncomment $mail->IsSMTP(); I get this error log:
2017-12-27 07:58:54 Connection: opening to smtp.gmail.com:465, timeout=300, options=array()
2017-12-27 07:58:54 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:465 (Network is unreachable) [/srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/SMTP.php line 325]
2017-12-27 07:58:54 SMTP ERROR: Failed to connect to server: Network is unreachable (101)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting in /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php:1726 Stack trace: #0 /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php(1481): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Wed, 27 D...', 'Hello World!\r\n') #1 /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php(1320): PHPMailer\PHPMailer\PHPMailer->postSend() #2 /srv/disk2/2564570/www/consorttest.dx.am/mailtest.php(23): PHPMailer\PHPMailer\PHPMailer->send() #3 /srv/disk2/2564570/www/consorttest.dx.am/mailtest.php(32): smtpmailer('to#mail.com', 'from#mail.com', 'yourName', 'test mail messa...', 'Hello World!') #4 {main} thrown in /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php on line 1726
You're not "using gmail as your relay" if you comment out isSMTP() because then it's not using SMTP at all, and will ignore all your SMTP settings. You're sending via your local mail server using PHP's built-in mail function.
When sending through gmail, you can't use arbitrary from addresses, though you can preset aliases in your gmail account.
You've based your code on a very old and obsolete example - use the gmail one provided with PHPMailer.
The most important part of the error output is: Network is unreachable - that probably means your ISP blocks outbound SMTP - are you by any chance using GoDaddy?
Next up, you have a basic misconfiguration: you're connecting to port 465 using SMTPSecure = 'tls', which means it will try to use SMTP+STARTTLS explicit TLS encryption, and that just won't work on port 465. This is a key reason to use the provided examples - they don't make basic errors like this.
Every one of these things is covered in the troubleshooting guide the error links to.

Sending email with large body is failing

When sending an email from C# with body being large is resulting in failure in sending email
Mailbox unavailable.
The email is working fine with a smaller body. I am using html body to true property..
Thanks,
Zafar
Code:
using (MailMessage _mailMsg = new MailMessage())
{
_mailMsg.From = new MailAddress(ConfigurationManager.AppSettings["mailFrom"].ToString());
_mailMsg.Body = mail.Body;
_mailMsg.Subject = mail.Subject;
_mailMsg.IsBodyHtml = true;
foreach (string strEmailIds in mailTo)
{
if (strEmailIds != null && strEmailIds != string.Empty && strEmailIds != "")
{
if (!_mailMsg.To.Contains(new MailAddress(strEmailIds)))
_mailMsg.To.Add(new MailAddress(strEmailIds));
}
}
//_mailMsg.CC.Add(ConfigurationManager.AppSettings["mailCC"].ToString());
using (SmtpClient _client = new SmtpClient(ConfigurationManager.AppSettings["Host"].ToString()))
{
if (_mailMsg.To.Count > 0)
{
_client.Send(_mailMsg);
}
else
{
_mailMsg.Subject = "No emails associated with the portfolio: " + account + " Original Email:" + mail.Subject;
_mailMsg.To.Add(new MailAddress(ConfigurationManager.AppSettings["mailSuppotTeam"].ToString()));
_client.Send(_mailMsg);
}
Oke, on thing it could be is that the mail server rejects big messages. Let exclude that one... I assume you have a local smtp mail server installed (check for telnet 127.0.0.1 25 that should give a sort of reply) configure the mail server [ConfigurationManager.AppSettings["Host"]] for 127.0.0.1, can you send big mails now?
If ConfigurationManager.AppSettings["Host"] is already the local SMTP server then:
a) stop that smtp service (Simple Mail Transfer Protocol) for a moment (via the command services.msc)
b) send a small email
c) go to c:\inetpub\mailroot\pickup and edit the message via notepad so that it becomes a BIG email
d) start the smtp service again (services.msc)
The issue was with sending email to cross domain email id and was resulting in the Generic exception
"Mailbox unavailable." May be this is one of the reason behind the above exception.

lua send mail with gmail account

I want to send email with my gmail account, I gave it a try, but no luck, so is anyone can give me a sample? Any suggestions would be appreciated. Thank you
I used lualogging api, the code is
require"logging.email"
logger = logging.email {
rcpt = "aaa#sina.com",
from = "bbb#gmail.com",
user = "bbb#gmail.com",
password = *****,
server = "smtp.gmail.com",
port = 587,
headers = {
rcpt = "aaa#sina.com",
from = "bbb#gmail.com",
subject = "[%level] logging.email test",
},
}
logger:error("error!")
You should look at LuaSocket, especially its SMTP module which can be used to send mail using your GMail account. You also need a SSL library, I use LuaSec which was designed to be used together with LuaSocket. This is the code I successfully used to send emails using my GMail account:
-- Michal Kottman, 2011, public domain
local socket = require 'socket'
local smtp = require 'socket.smtp'
local ssl = require 'ssl'
local https = require 'ssl.https'
local ltn12 = require 'ltn12'
function sslCreate()
local sock = socket.tcp()
return setmetatable({
connect = function(_, host, port)
local r, e = sock:connect(host, port)
if not r then return r, e end
sock = ssl.wrap(sock, {mode='client', protocol='tlsv1'})
return sock:dohandshake()
end
}, {
__index = function(t,n)
return function(_, ...)
return sock[n](sock, ...)
end
end
})
end
function sendMessage(subject, body)
local msg = {
headers = {
to = 'Your Target <target email>',
subject = subject
},
body = body
}
local ok, err = smtp.send {
from = '<your email>',
rcpt = '<target email>',
source = smtp.message(msg),
user = 'username',
password = 'password',
server = 'smtp.gmail.com',
port = 465,
create = sslCreate
}
if not ok then
print("Mail send failed", err) -- better error handling required
end
end
The code from Michal Kottman works properly but it fails (for me) when smpt server works on 587 port, using a pretty different way to accept mail to send (according wo what I read). Does anybody faced anything similar? I always obtain "wrong version number" on server working on port 587.

Smtp Server Timeout error

I am trying to send mail using SmtpClient and below is my code.
SmtpClient client_ = new SmtpClient("relay-hosting.secureserver.net", 25);
//client_.DeliveryMethod = SmtpDeliveryMethod.Network;
//client_.EnableSsl = true;
// client_.UseDefaultCredentials = false;
//client_.Credentials = new System.Net.NetworkCredential(_fromAddress, _password);
MailAddress from_ = new MailAddress(_fromAddress, _fromName);
MailMessage msg_ = new MailMessage(from_, from_);
msg_.Subject = "Subject";
StringBuilder body_ = new StringBuilder();
body_.AppendLine("Line1");
body_.AppendLine("===============================================================================================");
body_.AppendLine("Line2");
body_.AppendLine("===============================================================================================");
body_.AppendLine("line2");
body_.AppendLine("===============================================================================================");
msg_.Body = body_.ToString();
msg_.IsBodyHtml = true;
client_.Send(msg_);
I am getting TimeOut error. When Same smtp configuration using in email client on my machine, it send the mail immediately. I don't know what can be cause. Also when I used my Gmail account with gmail smpt server it worked.
Most consumer ISPs block port 25 to prevent you from running a mail server.
Therefore, you cannot connect to port 25 from your house.
You can ask them for an alternate port.
Try port 587; it's commonly used as well.