Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2005, 12:17 AM
Authorized User
 
Join Date: Apr 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default sending email in code

Hello,
I am developing an application in Visual Basic .NET 2003. My application requires sending an Email to the user's primary Email address. The message needs to be sent as discreetly as possible. I know how to open up Outlook Express and send the message(my Outlook express doesn't work and I don't like Outlook Express anyway). I have been experimenting with System.Web and SMTP unsuccessfully, as I am using XP Home Edition. I would appreciate any advise on how to send Email as discreetly as possible considering all Microsoft Windows Operating Systems.

 
Old May 2nd, 2005, 12:41 AM
Authorized User
 
Join Date: Apr 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

These are the exceptions I am getting using System.Web SMTP:

(MAIN EXCEPTION)
System.Web.HttpException: Could not access 'CDO.Message' object. ---

(INNER EXCEPTION)
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x8004020E): The server rejected the sender address. The server response was: 530 5.7.0 Must issue a STARTTLS command first

   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
   at System.Web.Mail.LateBoundAccessHelper.CallMethod(T ype type, Object obj, String methodName, Object[] args)
   at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args)
   --- End of inner exception stack trace ---
   at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args)
   at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
   at System.Web.Mail.SmtpMail.Send(MailMessage message)
   at Project_1.Notification.Email() in C:\Documents and Settings\******\My Documents\Visual Studio Projects\Project 1\Notification.vb:line 16
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x8004020E): The server rejected the sender address. The server response was: 530 5.7.0 Must issue a STARTTLS command first

   --- End of inner exception stack trace ---
   at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
   at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
   at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args)
   at System.Web.Mail.LateBoundAccessHelper.CallMethod(T ype type, Object obj, String methodName, Object[] args)
   at System.Web.Mail.LateBoundAccessHelper.CallMethod(O bject obj, String methodName, Object[] args)

 
Old May 2nd, 2005, 10:07 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

This issue comes down to SMTP server permission. The SMTP classes work quite well if you attempt to hit an SMTP server that will accept your message. The error message that you posted indicates that you are trying to send mail thru a server that doesn't want you to send mail thru it.

For most mail servers you can successfully send a message thru it if you meet one of several conditions:

1) You are sending mail to an address that the server recognizes (i.e. you talk to mail.mydomain.com and tell it you have a message for me@mydomain.com. The server handles the mailbox for me@ and accepts a message for it.)

2) You are sending a message thru an SMTP server to which you have already authenticated. This is how many email programs can send messages. You connect to your mailbox server and authentication with a mailbox (POP) login. The server recognizes traffic from your computer as legitimate because you logged in successfully within some time period.

3) You are sending a message from a computer with a permitted IP address. This could be either a public IP that the server knows about or an internal address (LAN). Most corporate email systems and broadband networks are set up this way. They'll accept mail from a LAN address (or public IP address that is within its realm of control) because it is assumed to be legitimate, but other connections are filtered out based on other criteria.

4) (Not 100% sure on this one). You (you@yourdomain.com) send a message to someone else (me@mydomain.com) thru the mail server that should recognize you as a legitimate address (mail.yourdomain.com). If the server can validate your address as legitimate it will accept the message to me.

These are the conditions I am familiar with. If you don't meet one of these, the server will reject your message because it is regarded as mail relay. Typically mail servers are not set up to accept mail relay because it promotes SPAM. It looks like you are falling victim to condition #4.

How you fix this problem is up to your system configuration.

-Peter
 
Old May 3rd, 2005, 02:20 AM
Authorized User
 
Join Date: Apr 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

So given the conditions, what I'm looking for is something universal that users can EASILY use. Whether its smtp or something else. My understanding was that Windows came with a smtp server that when using the system.web namespace without defining a server would default to it. And thats it. So... My question would be is there a way either configure the windows smtp server to accept and send these messages or is there an alternate route(having them send an email from their primary Email address to their primary Email address)? The main factor is low key. I need it to be sent "automatically". Also aside from the Email issue I'm curious if the msdn article on sms using the compact framework would work from a windows app?

 
Old May 3rd, 2005, 07:29 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can make your application send email automatically. You just need to configure it to talk to an SMTP server that will accept the message as I described above.

(Non version specified) Windows doesn't come with an SMTP server by default. Windows machines with Internet Information Server have a SMTP server (or virtual server). However, I've had bad luck with this. Sometimes a message will get accepted but I'll never see it delivered.

Using the .NET SMTP method, if you don't specify the SMTP server name, I do believe that it will default to "localhost". However, this will only be successful if your localhost has an SMTP server running.

-Peter
 
Old May 3rd, 2005, 04:57 PM
Authorized User
 
Join Date: Apr 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What about Winsock? I have been searching and have seen some information on using winsock to send email. I am not very familiar with tcp/ip or winsock but is this an option?

 
Old May 3rd, 2005, 09:09 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

In the end, you still need to talk to an SMTP server that will accept your mail message. Regardless of how you send the mail you will be restricted by limitation.

-Peter
 
Old May 8th, 2005, 01:54 PM
Authorized User
 
Join Date: Apr 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

OK. Say I set up one of my old pc's as a server. If I specify that computers ip address as the smtp server would it relay the message?(Given it has an smtp server installed)

 
Old May 9th, 2005, 03:31 AM
Authorized User
 
Join Date: Apr 2005
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have installed several different smtp servers and I'm still getting the same exceptions just as if i had never installed them. What is the problem why is this not working?

 
Old May 9th, 2005, 06:06 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Are you still getting "The server rejected the sender address." errors? This doesn't mean that the server isn't working, it just means that the server doesn't like your addresses. Based the SMTP rules, you might still be missing the configuration that allows messages.

You could configure the SMTP server to accept mail relay (NOT advisable if the server is accessible publicly, but OK if it's only visible on your LAN).

-Peter





Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending EMAIL charleshua BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 16 September 3rd, 2008 12:27 AM
code for Sending Email in jsp mhadz JSP Basics 0 January 12th, 2007 03:55 AM
Sending email maitias C# 2005 2 February 17th, 2006 11:24 AM
email sending msrnivas .NET Web Services 6 June 26th, 2004 06:59 AM
sending Email thru ASP Code zaeem Classic ASP Basics 4 November 13th, 2003 04:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.