Email using asp.net and System.Web.Mail

  • Thread starter Thread starter JSzucs
  • Start date Start date
J

JSzucs

I wrote a little code snipet in Asp.Net to send a default
message to my outlook email address. That works fine,
since the SMTP virtual server default domain is same
domain as my outlook mail server:

myMessage.To = "(e-mail address removed)"
myMail.SmtpServer = "mail.universalmoney.com"

But when I try to sent to (e-mail address removed), I get
the following error:

The server rejected one or more recipient addresses. The
server response was: 550 not local host page.nextel.com,
not a gateway.

Now, I have seen this problem come up in Outlook, where
you must click the "My server requires authentication"
box, to get around this error. But I can't find a similar
box in the SMTP virtual Server properties. Do you know how
I can get around this problem?

Thanks for your help,
JSzucs
 
Hello JSzucs,

Thanks for your post. I'd like to share the following information with you:

Would you please tell me what mail.universalmoney.com is, a server running
SMTP Sevices or an Exchange Server?

1. If it's SMTP sever, we should onfigure the it to allow relay and set
Outbound Security by the following steps:

a. Go to "Start" -> "Control Panel" -> "Administrative Tools" -> "Internet
Information Services"
b. Right click "Default SMTP Virtual Server", select "Properties".
c. In "Access" panel, click "Relay", choose "All except the list below"
radio button, click OK.
d. Open "Delivery" panel, click "Advanced", in the "Smart host" setting,
input the smarthost or exchange or remote smtpserver name or ip address.
e. Click "OK" button, click "Outbound Security" in "Delivery" panel, choose
"Basic Authentication", input the user name and password for your email
account.

2. If it's an Exchange Server, I recommend using CDOSYS instead of SmtpMail
(System.Web.Mail) as CDOSYS gives
more configuration flexibilty. Here is the code for sending email using
CDOSYS in VB .NET using Port:

Sample:
1) Start Microsoft Visual Studio .NET. On the File menu, click New and then
click Project. Select Console Application from the Visual Basic Projects
types. Module1.vb is created by default.

2) Add a reference to the Microsoft CDO For Windows 2000 Library. To do
this, follow these steps:
a. On the Project menu, click Add Reference.
b. On the COM tab, locate Microsoft CDO For Windows 2000 Library and click
Select.
c. Click OK in the Add References dialog box to accept your selections. If
you receive a prompt to generate wrappers for the libraries you selected,
click Yes.

3) Follow the same steps to add a reference to the Microsoft ActiveX Data
Objects 2.5 Library

4) In the code window, replace the whole code with:
Imports System.Reflection
Module Module1
Sub Main()
Dim oMsg As CDO.Message = New CDO.Message()
Dim iConfg As CDO.Configuration
Dim oFields As ADODB.Fields
Dim oField As ADODB.Field

iConfg = oMsg.Configuration
oFields = iConfg.Fields
oField =
oFields("<http://schemas.microsoft.com/cdo/configuration/sendusing>")
oField.Value = 2 'CDO.CdoSendUsing.cdoSendUsingPort
' TODO: Replace with the Port you want to use (Needs to be the same
' port that the SMTP server is using)
oField =
oFields("<http://schemas.microsoft.com/cdo/configuration/smtpserverport>")
oField.Value = 25

' TODO: Replace with your SMTP server
oField =
oFields("<http://schemas.microsoft.com/cdo/configuration/smtpserver>")
oField.Value = "<SMTP Server>"
oFields.Update()
oMsg.Configuration = iConfg
oMsg.TextBody = "Test message body."
oMsg.Subject = "Test SMTP Message Send using port"
oMsg.From = "(e-mail address removed) <mailto:[email protected]>"
oMsg.To = "(e-mail address removed) <mailto:[email protected]>"
oMsg.Send()
oMsg = Nothing
iConfg = Nothing
oFields = Nothing
oField = Nothing
End Sub
End Module

5) Modify code where you see TODO.

Please feel free to let me know if you have any problems or concern.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 
Back
Top