Windows 2008 script error when mail server offline - windows

Everything works perfectly until our mail server goes offline. But when the mail server cannot be reached our scripting fails. When a user logs into the website th server sends a notice to admin by email. But if the mail server is offline that login fails and returns a server error.
We are using CDOSYS and using the local SMTP server to relay to our main mail server. The code is straightforward...
Set ObjSendMail = CreateObject("CDO.Message")
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = artiscart_mail_server
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
ObjSendMail.Configuration.Fields.Update
ObjSendMail.To = strEmail
ObjSendMail.Subject = "Login activity"
ObjSendMail.From = strEmail
ObjSendMail.TextBody = strEmailBody
ObjSendMail.Send
Set ObjSendMail = Nothing
A similar thing happens when we send a newsletter and one of the emails is a dud. On Windows Server 2003 we had no problems whatsoever, but on Windows Server 2008 the same scripting fails.
Is there some way that I can configure the local SMTP server to ignore errors and move on?

To avoid all errors caused by mail server failure and bad email addresses, simply add this first line above the last line like so...
On Error Resume Next
ObjSendMail.Send

Related

Cannot send emails to yahoo using mailkit

I am creating a system that sends emails (pricing, orders, invoices, etc) to out customers. But due to the number of emails that ends up being, we hit limits when trying to send through gmail or any other mail client. And since these are all customer specific emails using a bulk sending client is not ideal.
So I have created a system using mailkit and others to send our emails from our own servers without needing to set up a relay or email server for sending. This works great with everyone (Gmail, outlook, etc) except for yahoo. For some reason when I connect and mailkit tries to switch to STL (via startstl) yahoo sends garbage and mail kit fails.
I have enabled all ssl and tsl protocols. And I have ServerCertificateValidationCallback always to return true. In fact ServerCertificateValidationCallback doesn't even get called.
The errors that are thrown start with:
A call to SSPI failed, see inner exception
then
The message received was unexpected or badly formatted.
If I try to connect to any of the other SMTP ports 465 or 587 the system just hangs.
This all happens when connecting, before the email is sent. So it cannot be a DKIM issue. And the SPF record is set up correctly. We don't have the reverse dns setup because we plan on sending from multiple servers with different IPs.
I don't know why yahoo is being so difficult.
Tried talking with MailKit, tries allowing all TLS and SSL connections. Tried finding any YAHOO support.
using (var client = new SmtpClient())
{
client.LocalDomain = "MyDomain";
// right now we don't care about all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (s, c, h, e) => {
return true;
};
client.SslProtocols = System.Security.Authentication.SslProtocols.Tls11 |
System.Security.Authentication.SslProtocols.Tls12 |
System.Security.Authentication.SslProtocols.Tls |
System.Security.Authentication.SslProtocols.Ssl3 |
System.Security.Authentication.SslProtocols.Ssl2;
client.CheckCertificateRevocation = false;
client.Connect("mta6.am0.yahoodns.net", 25, false); //<--- fails here
client.Send("test", fromMailBoxAddress, recipientsEmailBoxAddresses);
client.Disconnect(true);
}
To answer your question, I might have an idea why Yahoo is being so difficult - it's possibly your message construction. Verify your MimeMessage has the same exact email address for your From and Sender addresses. Ensure your ReplyTo only contains the Sender email address. I had both the sender and recipient email addresses in the ReplyTo and Yahoo did NOT like that. And, of course, you are using a Yahoo App password for authentication. Once I made these two changes, Yahoo sent the email successfully.
Settings
client.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
client.DeliveryStatusNotificationType = mail.DeliveryStatusNotificationType.Full;
await client.ConnectAsync("smtp.mail.yahoo.com", 587, SecureSocketOptions.StartTls);
await client.AuthenticateAsync(yourEmailAddress#yahoo.com, yourYahooAppPassword);
await client.SendAsync(Message);
await client.DisconnectAsync(true);
Research
Bad message construction breaks one of Yahoo's many policies. This was ONLY happening with SMTP via Yahoo. SMTP via Gmail and Outlook work fine. I kept comparing a simple MailMessage with MimeMessage message construction. MailMessage sent, MimeMessage failed, I kept getting a 550 request failed; mailbox unavailable response from Yahoo every time with my MimeMessage. I verified by using ProtocolLogger. My From was empty and that is one issue, and, I had the recipient in my ReplyTo. If I merely added the sender to the ReplyTo, it still throws that same 550 error. I had to ensure the sender was the only email in the ReplyTo.
Hope this helps.
Use client.Connect("mta6.am0.yahoodns.net", 25, SecureSocketOptions.None); if you want to disable STARTTLS or use client.Connect("smtp.mail.yahoo.com", 587, SecureSocketOptions.Auto); which works fine.
Not sure where you are getting "mta6.am0.yahoodns.net" from, but I can't even make a normal socket connection to that address.

How to fix "The remote name could not be resolved"

I've created asp.net web-api , In the controller I try to call an external URL to send sms(the sms URL I get from the sms provider company )
When I try to call the controller I get this error
"The remote name could not be resolved"
This error only happened on the server ,On the localhost it's working fine
I am using Azure hosting
I tried to add some code to the webconfig
<defaultProxy enabled="true" useDefaultCredentials="true">
I also tried to call the sms URL in a different way
HttpClient client = new HttpClient();
response = client.GetAsync(urlParameters);
I've read some solutions about allowing access for the external link(SMS) on firewall and DNS of the server but it's already configured on azure server
Here is my code
string webAddress = "http://----------------";
string SomeData = System.Text.Encoding.Default.GetString((new
System.Net.WebClient()).DownloadData(webAddress));
I want my web api to send the sms without any error on the server side
Finally ,I solved the problem by replacing the SMS provider URL by their IP Address.
Here is an example of my solution :
Ex : http://123.123.123.123:12345/TEST/Para?i1=

Not able to Enable postfix for outbound relay via Gmail on Mavericks

I am trying to enable postfix for outbond relay via gmail
I am following all the steps from this site.
But not able to receive mail.
And got the following msg in file located at /var/mail
host gmail-smtp-in.l.google.com[74.125.129.27] said:
550-5.7.1 [106.78.175.213] The IP you're using to send mail is not
authorized to 550-5.7.1 send email directly to our servers. Please use the
SMTP relay at your 550-5.7.1 service provider instead. Learn more at 550
5.7.1 http://support.google.com/mail/bin/answer.py?answer=10336
j5si48631733pbs.31 - gsmtp (in reply to end of DATA command)
Actually I am integrating bot and want to receive mail on success or failure. But not receiving any mail so I googled and found that I have to enable postfix for outbound.
I have also try with mailx <my gmail address> on terminal but didn't receive any email.
I'm going to try to shed some light on some fun I've had in a similar situation. I have the Server 3.0 installed however so where things live can get irritating to track down.
In my situation postfix is running /Library/Server/Mail/Config/postfix. But its moved around from release to release which makes your old configuration start to clutter up your build.
Within your postfix, you should have a main.cf.
I added a section:
>sudo nano main.cf
smtpd_recipient_restrictions = permit_sasl_authenticated permit_mynetworks
reject_unauth_destination
smtpd_use_pw_server = yes
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
smtpd_pw_server_security_options = cram-md5,digest-md5,gssapi,login,plain
smtpd_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
relayhost = [smtp.gmail.com]:587
CTL + O, enter to save
Its important to note now we have to deal with this /etc/postfix/saslpasswd
sudo nano /etc/postfix/saslpasswd
[smtp.gmail.com]:587 first.last#gmail.com:YourPassword*9
CTL+O, enter to save.
There are a couple more commands to issue that I didn't find obvious.
sudo postmap /etc/postfix/saslpasswd
sudo postfix reload
Hope that helps. The Base Mail / Server with the pretty on/off button doesn't seem to do that lat part for you. And I reset my password from time to time. When I do, I have to remember these paths, then make sure I issue those last two commands or the saslpasswd.db gets out of sync.
Good Luck

VBScript to send email without running Outlook

I have written an automated test that runs each night, and I would like to email the results each night once the test is finished.
In order to do this I attempted to put the following at the end of my batchfile:
Set MyApp = CreateObject("Outlook.Application")
Set MyItem = MyApp.CreateItem(0)
With MyItem
.To = "a#a.com"
.Subject = "Subject"
.ReadReceiptRequested = False
.HTMLBody = "resport"
End With
MyItem.Send
However, this is causing the email to not send because my Outlook is not open, as the test is run in the background, and I have no access to the UI.
Is there anyway to send this email without actually running outlook on the machine.
Thanks!
You can send email without Outlook in VBScript using the CDO.Message object. You will need to know the address of your SMTP server to use this:
Set MyEmail=CreateObject("CDO.Message")
MyEmail.Subject="Subject"
MyEmail.From="name#domain.com"
MyEmail.To="a#a.com"
MyEmail.TextBody="Testing one two three."
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'SMTP Server
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
'SMTP Port
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
MyEmail.Configuration.Fields.Update
MyEmail.Send
set MyEmail=nothing
If your SMTP server requires a username and password then paste these lines in above the MyEmail.Configuration.Fields.Update line:
'SMTP Auth (For Windows Auth set this to 2)
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
'Username
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername")="username"
'Password
MyEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword")="password"
More information on using CDO to send email with VBScript can be found on the link below:
http://www.paulsadowski.com/wsh/cdo.htm
Yes. Blat or any other self contained SMTP mailer. Blat is a fairly full featured SMTP client that runs from command line
Blat is here

Error sending email

I created a simple application at: graficaromana.com.br
In the contact form (http://graficaromana.com.br/Contato) when I try to send an email I get an error.
Locally the mail is sent normally without any error.
Is there some setting I have to do on the host? in the domain?
Error:
System.Net.Sockets.SocketException A connection attempt failed because
the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to
respond 209.85.225.108:25
See the code for more details in link: https://gist.github.com/1149028
looks like the remote host has maybe a separate server they use for sending mail out or that you have to be whitelisted with the host in order to send mail and a username and password may be required. have not looked at your code but i see them kind of errors when there is a firewall involved and the machine trying to send does not have access through the firewall, as the firewall does not respond at all you get an answer like ' The server did not respond in a timely manner' or 'the server did not respond after a certain amount of time' i am assuming that before you posted on here that you have asked the hosting provider about sending mail, and what there preference is on how this should be carried out? right?
if so please provide info on what they have said
here is a sample of code to send email:
var smtpClient = new SmtpClient();
var message = new MailMessage();
smtpClient.port = 25;
message.from = "test#test.com";
message.To.Add("me#workemail.com,client#office.com";
message.Subject = "Contact from website";
message.IsBodyHtml = true;
message.Body = "<html><head></head><body>TEST</body></html>"
try {
smtpClient.Host = "relay.server.you.have.from.host";
smtpClient.Send(message);
} catch( Exception ) {
// host is down or we are local try other servers
// here you can have more try / catch
smtpClient.Host = "127.0.0.1"
smtpClient.Send(message);
}

Resources