Exchange 2010 Authentication Issues - email

So I am trying to send an automated message from an Excel VBA backend. I'm very competent in my VBA skills and have used the method below with great success in the past. I am having issues using this method in my new environment and I know it has something to do with the configuration of the Exchange server, the issue is that the guy who manages the exchange server nor I are Exchange experts.
Public Function SendEmail(
txtTo As String,
txtSubject As String,
txtBody As String,
Optional txtSender As String = vbNullString,
Optional txtCC As String = vbNullString,
Optional txtBCC As String = vbNullString)
Dim objMsg As Object, objconfig As Object, objFields As Object
Set objMsg = CreateObject("CDO.Message")
Set objconfig = CreateObject("CDO.Configuration")
Set objFields = objconfig.fields
'Set the email configuration
With objFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With
'Apply the various fields to the email object
With objMsg
.Configuration = objconfig
.From = txtSender
.Subject = txtSubject
.To = txtTo
.Cc = txtCC
.Bcc = txtBCC
.TextBody = txtBody
.Send
End With
SendEmail = IIf(Err.Number = 0, True, False)
'clean up
Set objMsg = Nothing
Set objconfig = Nothing
Set objFields = Nothing
End Function
I am attempting to send to a distribution group which requires authentication. We've figured out how to remove that "feature" to send an email but this is not ideal. I've tried using basic/clear trust (1) for the authentication method, supplied my username and password to the required fields in the configuration object and still no dice. When I send an email from Outlook I have no issues sending to an email that requires authentication, but when using CDO Exchange won't allow me to authenticate. It also never resolves the sender address, not sure if that is related or not but for the sake of full disclosure there it is.
I know that the Exchange/SMTP server is configured to allow for anonymous sending, but that seems to be the only option that CDO will use.
I'm at my wits end. Any Exchange gurus out there that might be able to offer some suggestions?
Thanks,
Chad

Well, I finally managed to solve my own issue. If anyone else is having similar issues I thought I'd share. It turned out to be a port issue.
The standard ports for exchange are 25 and 465 for SSL (I believe).
In this instance, port 25 was configured for sending anonymously from behind our firewall (by printers & fax machines mainly). I tried using port 465 but it reported back that the port did not exist.
After much digging on the exchange server I found that some arbitrary port number was used to configure the authenticated messages against. Once I hardcoded the correct port number in the code above, I had no issues getting it to work. Happy coding!

Related

How to set from email address when sending email by automation with outlook

In a legacy vb6 program I am sending email using the full version of outlook (not outlook express) using the code below. Works great.
Now the user wants the 'from:' address to be different for different uses so that when the email is replied to the response will show up in that users inbox in outlook. Currently the email from is the main business email address.
I thought that was an easy fix; I just need to set the .from property in the OutMail object, however it seems there is no '.from' property in the OutMail object. (It may be called something else?)
So at this point I'm wondering how it works now, with no .from specified, and I assume the user has multiple email accounts setup in outlook, it is using the main email for the business, not individual users.
How can I specify a from email address using this technique?
Dim mOutlookApp As Object
Set mOutlookApp = GetObject("", "Outlook.application")
Dim olNs As Object
Set olNs = mOutlookApp.GetNamespace("MAPI")
olNs.Logon
Dim OutMail As Object
Set OutMail = mOutlookApp.CreateItem(0)
'Set the To and Subject lines. Send the message.
With OutMail
.To = txtTo
.CC = txtCC
.Subject = txtSubjext
.HTMLBody = txtBody & vbCrLf
Dim myAttachments As Object
Set myAttachments = .Attachments
vAttach = Split(mAttachments, ",")
For i = 0 To UBound(vAttach)
myAttachments.add vAttach(i)
Next i
Dim myFolder As Object
Set myFolder = olNs.GetDefaultFolder(5) 'olFolderSent
Set .SaveSentMessageFolder = myFolder
StatusBar1.Panels(1).Text = "Status: Sending"
.send
End With
If all you care about is that the reply goes to the right mailbox, set that email address as the reply address. You can do that using Mailtem.ReplyRecipients.Add.

Send email via MATLAB

I need to send an email via MATLAB and I've read the instructions for sendmail and lots of answers around here. I've tried 3 email providers and I can't really use any of them:
Gmail: I can only send email when I deactivate my anivirus
Hotmail and Yahoo: Error using sendmail (line 171) Exception reading response; Connection reset
Hotmail and Yahoo (antivirus off): Error using sendmail (line 171) Exception reading response; Unrecognized SSL message, plaintext connection?
Here's the code
mail = 'user#service.com';
password = 'passwordgoeshere';
setpref('Internet','SMTP_Server','smtp.server.com');
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port',port);
sendmail(mail,'Test from MATLAB','Hello! This is a test from MATLAB!')
I've used the following variables:
Gmail: smtp.gmail.com port=465
Hotmail: smtp.live.com port=465 and port=587
Yahoo: smtp.mail.yahoo.com port=587
Since deactivating the antivirus is not a good option, can anyone help me solving this?
Thank you
An alternative way on linux is to run a command line that send the email.
unix('echo "message" | mail -s "subject" example#gmail.com');
A similar method should be available for windows.
For Gmail
Change your settings to allow less secure apps to access your account. Go to the "Less secure apps" section in My Account.
Next to "Access for less secure apps," select Turn on. (Note to Google Apps users: This setting is hidden if your administrator has locked less secure app account access.)
In Matlab:
mail = 'user#otherdomain.com';
password = 'myPassword';
% Set up the preferences
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server','smtp.gmail.com');
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
% The following is necessary only if you are using GMail as
% your SMTP server.
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
subject = 'Test subject';
message = 'Test message';
sendmail(mail,subject,message)
Simply declare
mail = 'user';
Drop the extension #service.com for the variable mail.

Delayed receiving the email message using the SMTP server

I already deployed the Email Service I developed on the Chicago Server. Last Friday 11:30pm in Philippine time, I tested the sending and it run's properly, but when I checked my email there's no message in inbox or spam. And then, Saturday 1:30am, I've noticed that I received the message that I tested last Friday.
Please advice me guys! thanks!
My Questions is:
a.) Do I need to configure something on the Server to make the real time receiving on emails?
here's my code:
//send email
MailMessage objEmail = new MailMessage(new MailAddress(ConfigurationManager.AppSettings["emailAdd"].ToString()), new MailAddress(ConfigurationManager.AppSettings["emailAdd"].ToString()));
objEmail.Subject = "Test";
objEmail.Body = "CODE:" + _Message;
objEmail.Priority = MailPriority.High;
SmtpClient SmtpMail = new SmtpClient();
SmtpMail.Host = "localhost";
SmtpMail.Send(objEmail);
Put this one on your code:
SmtpMail.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
And also, configure the relay restrictions on the SMTP server that will allow your 120.0.0.1/localhost..
Last, configure the firewall and port forwarding on the server.
I hope this will help you..

Using CakePHP's Email component

I try to send a simple Email via CakePHP's Email Component. I'm using following code from the cookbook documentation:
$this->Email->from = 'Irgendjemand <irgendjemand#example.com>';
$this->Email->to = 'Irgendjemand Anderes <irgendjemand.anderes#example.com>';
$this->Email->subject = 'Test';
$this->Email->send('Dies ist der Nachrichtenrumpf!');
The send()-method does only return a boolean value with the value false - but no error or warning occurs.
Does somebody have a solution for that?
Have you tried changing the delivery options? There are three options: mail, smtp and debug.
$this->Email->delivery = 'debug';
$this->Email->send('test message');
debug($this->Session->read('Message.email'));
You can debug with EMail. Set the delivery to debug and the email message will be set to Session.message:
if (Configure::read('debug') > 1) {
$this->Email->delivery = 'debug';
}
$ret = $this->Email->send();
if (Configure::read('debug') > 1) {
pr($this->Session->read('Message.email'));
}
Which OS are you on? If Windows, this note may be of interest:
Note: The Windows implementation of mail() differs in many ways from the Unix implementation.
...
As such, the to parameter should not be an address in the form of
"Something <someone#example.com>". The mail command may not parse this properly while talking with the MTA.
Secondly, it may just be the case that no mail server will accept outgoing mail from your local machine due to spam protection. I have often seen that the same mail() function will not work locally, but works fine once uploaded to a trustworthy server. You could try to use an authenticated mail relay in that case (SMTP).

Remove Confirmation Box vbs script

I have the following code where i could send mail through my configured outlook.
I can run this vbs using a rule in my outlook which in turn send a mail to the email specified in the script
But i am getting a confirmation box asking a virus or not while running this script to send a mail.
How to get rid of this confirmation box to make always allow to send mails.
Dim ToAddress
Dim MessageSubject
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
ToAddress = "John.Smith#place.com" ' change this...
MessageSubject = "My Subject"
MessageBody = "DATA"
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
ns.logon "","",true,false
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf
' validate the recipient, just in case...
Set myRecipient = ns.CreateRecipient(ToAddress)
myRecipient.Resolve
If Not myRecipient.Resolved Then
MsgBox "unknown recipient"
Else
newMail.Recipients.Add(myRecipient)
newMail.Send
End If
Set ol = Nothing
I believe your being hit by the now built-in security feature(s) that Microsoft put in place a couple years back with a security patch. The only way I know around it to is to digitally sign the code and then import the certicate that was used to sign that code into the certificate store, or better yet use the Redemption DLL. From the Redemption DLL site:
Outlook Redemption works around
limitations imposed by the Outlook
Security Patch and Service Pack 2 of
MS Office 98/2000 and Office
2002/2003/2007 (which include Security
Patch) plus provides a number of
objects and functions to work with
properties and functionality not
exposed through the Outlook object
model.
The DLL can be downloaded from here: http://www.dimastr.com/redemption/download.htm, and if you look around you can find several examples of how to use it. Here is one to get you started: http://www.utteraccess.com/forums/printthread.php?Cat=&Board=80&main=409393&type=thread
Also please note the peviously posted and answered questions:
How to avoid Outlook security alert when reading outlook message from C# program
Outlook nagging dialog about macro