How to send email by using Exchange server in Classic ASP? - asp-classic

I am migrating a classic asp application to a new server, however smtp server is not allowed in the new server, can someone give me a tips about how to send email via the exchange server?

Classic ASP's CDOSYS component has a remote server parameter you could use to send emails via the Exchange server on port 25.
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail#mydomain.com"
myMail.To="someone#somedomain.com"
myMail.TextBody="This is a message."
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
%>

Related

CDOSYS error '80040213' - failed to connect to server

I have a Windows Server 2003 R2 running IIS and a website using classic ASP.
Trying to get it to use CDOSYS to email using our own (externally) hosted office365 exchange server.
I get the following error
CDO.Message.1 error '80040213'
The transport failed to connect to the server.
Which usually means one of 3 problems:
1. Incorrect SMTP server / port
2. Incorrect login/password
3. FROM address not valid according to SMTP server (wrong domain)
The SMTP server and port are correct according to supplier.
The login/password is correct as I can log into the mail account using those details
The FROM address is correct as that is the account I am using to log in.
I can telnet to the exchange server from the web server on that address and port, so a connection can be made from the server at least.
So at the moment I'm at a loss as to what the problem might be.
Does anyone have any pointers as to anything else I need to look at?
This is the config the website is using
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.office365.com"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=587
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 20
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
Did you setup an SMTP relay in Office 365?
From the Office 365 Admin go to:
Admin > Exchange
Mail Flow > Connectors
Click add new SMTP relay connector
Select from "your organization's email server" to "office 365"
Give the connector a name and description
Select verify by IP address and add your web server IP
Save
Try Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
With Office 365, cdo seems to prefer port 25, even when using authentication.
Here's a tried and tested configuration if it helps
Set iConfg = Server.CreateObject("CDO.Configuration")
Set Flds = iConfg.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "myusername"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypassword"
.Update
End With
objMail.Configuration = iConfg
Try
.Item("http://schemas.microsoft.com/cdo/configuration/smtpsendtls") = 1
instead of
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
Well I eventually got this solved.
I needed to use a different method of connecting to the office365 server.
So all is working as it should now.

Is my username and password sent plaintext when connecting to my remote sql

Is our username and password that is sent over the network to connect to a 2008 sql db plaintext?
For instance
SqlConnection conn = new SqlConnection(connectionString);
Is the password and username sent plain text to the server for the initial handshake?
This TechNet article claims that the credentials for SQL 2008 are always encrypted:
http://technet.microsoft.com/en-us/library/ms189067(v=sql.100).aspx
Credentials (in the login packet) that are transmitted when a client
application connects to SQL Server are always encrypted.
There are optional items you can add to your connection string that will also enable encryption for other types of SQL Server communication that may be worth investigating if point-to-point security is a concern for your application.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring.aspx

mailsending issues with new mailserver

i am using for send mail my smtp server is "xxx.xx.x", its working fine. But now i am changing the mail server for emails. i am using new mail smtp server ip address is "xxxxxxx.xxx.xxx", in this case get the error like "The server rejected one or more recipient addresses. The server response was: 554 5.7.1 : Client host "
i am using the bellow code
Dim eMail As MailMessage = New MailMessage
eMail.To = "xxxxxxx"
eMail.BodyFormat = MailFormat.Html
eMail.From = "xxxxxxxx"
eMail.Subject = "intermedia mail test using 127.0.0.1"
eMail.Body = sMsg
SmtpMail.SmtpServer = "xxxxxxx 'AppSettings("MailServer")
SmtpMail.Send(eMail)
Thanks in advance
You are getting this error because the mail server is configured to only send mail from certain domains or the client is not in its list of accepted senders.
You need to get in touch with the mail server administrator and ask them to allow the IP address of the machine that the application resides on or send the mail using an address in the correct domain.
http://www.ietf.org/rfc/rfc1893.txt

configuring smtp in iis 7 for sending emails from classic asp application

I want to configure the smtp server on iis7. Its a website done on classic asp from which i am sending email. I get the error code as -2147220973.
I have configured the email address and stmtp server name in IIS 7
Is there anything else need to be configured ? or what is the error code means ?
CDOSYS Error: Error Number:
-2147220973 Error Source: CDO.Message.1 Error Description: The
transport failed to connect to the
server.
Looks like IIS is not able to connect to SMTP server, make sure you are using the correct SMTP server, some web hosts, such as GoDaddy require you to use their SMTP server to control spam issues. Check you web hosts support documentation. Also CDOSYS, the e-mail component used in ASP doesn't read the IIS configuration, as in IIS 7 that is used for ASP.NET and not ASP Classic. IIS 7 is configured by default to use localhost.
Take a look at the code below and make sure your code is using the correct SMTP server.
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail#mydomain.com"
myMail.To="someone#somedomain.com"
myMail.TextBody="This is a message."
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
%>
http://www.w3schools.com/asp/asp_send_email.asp
I have also written a simple ASP function that uses a Dictionary object to send e-mail with CDOSYS. That can make sending e-mail a little bit easier in ASP Classic.
http://www.simplecontactus.com

cdoSendUsingPort gives 8004020f but cdoSendUsingPickup works

I am using cdo to send email the following code fails
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "localhost"
.Update
End With
When I send an email I get the following error
8004020f
I then changed the code to the following:
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPickup
.Item(cdoSMTPServer) = "localhost"
.Update
End With
The email sends without a problem. What steps could I take to troubleshoot why cdoSendUsingPort is not working?
With cdoSendUsingPort, CDO tries to open a connection to the SMTP server you specify (in your case, localhost) on TCP port 25. I guess you're not running an SMTP server on your machine, so nothing is listening on port 25 and the call fails.
With cdoSendUsingPickup, CDO forwards the message to the pickup directory of your local IIS instance for later processing. I guess you have IIS installed on your machine and its SMTP module is configured to use pickup, so the call succeeds.
Professor Google finds (in order):
- Several options: server disallows anonymous relaying, server rejects specific recipient domains, recipient is rejected by SMTP server in unexpected way, and/or proxy or firewall settings are blocking the mail.
- Your mailserver is configured to not relay from your source machine.
- ... and several more things which boil down to the first link listed.
Some of these things you can test directly by telnet-ing from the sending machine to the mailserver, performing a normal SMTP interaction, and seeing what messages are displayed.

Resources