smtp success, and troubles...

juggernot

Well-known member
Joined
Sep 28, 2006
Messages
173
Programming Experience
Beginner
K, I finally got my smtp code working. here is my code
Dim obj As SmtpMail

obj.SmtpServer = "smtp.gmail.com"
obj.Send("myemail@gmail.com", "youremail@hotmail.com", "This is a test", "Hey, this is a test. ")

This worked on a computer at my school, but on my home computer it did not. I got another cdo.message error. Can someone help me out?

 
The CDO error doesn't mean a thing, as I have told you before. I also told you about the systemwebmail site. What is the innerexception(s)? The innerexception may have a more descriptive innerexception of its own, so you have to iterate them. You can throw them up in a messagebox and read them carefully and/or send the text to clipboard to post if you don't understand what they are saying. See this code if you don't know how to get the innerexception: http://www.systemwebmail.com/faq/4.1.aspx
 
I followed the link and changed my code accordingly. However, It is having a problem with the 'response'.write . I believe I used the code i found thru your link correctly, but it says that 'response is not delcared'. The only difference is that he made a mail message, where as I used smtpmail. What should I declare it as? or is something else the matter?

Code:

Dim strTo As String



Dim obj As SmtpMail
obj.SmtpServer = "smtp.bluebottle.com"

Try
obj.Send("email@bluebottle.com", Me.TextBox1.Text, Me.TextBox2.Text, Me.RichTextBox1.Text)
Catch ex As Exception
response.write(("the following exception occured:" & ex.ToString()))
while not
response.write("------------------------")
Response.Write(("The following InnerException reported: " + ex.InnerException.ToString()))
ex = ex.InnerException
End While
End Try

P.S One reason it may not be working is that my isp may be blocking port 25(smtp). if it is, could you tell me a way to get around that problem?
 
Instead of Response object that is used in ASP.Net you can output to Debug and/or Messagebox and/or Clipboard.

No ISPs are blocking the default mail protocol port 25. Have a look at the innerexception.
 
ok, I'll pase the innerexception. Just to warn you, It is VERY LONG.


the following exception occured:System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040213): The transport failed to connect to the server.

--- 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(Type type, Object obj, String methodName, Object[] args)
at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
--- End of inner exception stack trace ---
at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)
at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
at System.Web.Mail.CdoSysHelper.Send(String from, String to, String subject, String messageText)
at System.Web.Mail.SmtpMail.Send(String from, String to, String subject, String messageText)
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Roxie Robertson\Desktop\Copy of email\WindowsApplication1\email.vb:line 169------------------------The following InnerException reported: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040213): The transport failed to connect to the server.

--- 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(Type type, Object obj, String methodName, Object[] args)
at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)------------------------The following InnerException reported: System.Runtime.InteropServices.COMException (0x80040213): The transport failed to connect to the server.
 
This is the meaningful part: "The transport failed to connect to the server." This mean the app could not connect to the specified smpt server. There could be several reasons for this. Remote server could be down. Remote server could have blocked usage from outside domains. General connection trouble with ISP. Local firewall could be blocking, and note that sending to a smtp servers port 25 doesn't use port 25 locally (I typically see various ports around 4000 used for this locally), so it is usually the application that have to be granted access if this is the case.

The ISP has given you specifications for your outgoing smtp mail server and port to be used with your internet account. If it work in your regular mail app it should work from VB.Net too.
 
I got it to work. It's really wierd. At home, I had to use my ISP's smtp server, but at school I could use any smtp server. Strange, but it works now.... I'm not going to question it....
 
If you ever need to test network connectivity restrictions etc, you can try to telnet the server which your app will use?

telnet smtp.server.com 25 [enter]

see if you get a connection , it should help diagnose whats happening.
 
I got it to work. It's really wierd. At home, I had to use my ISP's smtp server, but at school I could use any smtp server. Strange, but it works now.... I'm not going to question it....
It's up to each provider of a smpt server what usage retrictions they set, this is very understandable since the smpt server initially is available to any internet user in the world, they usually limit what ip ranges (domains) it will accept calls from, some require user authentication also for sending mail (usually this is only done when recieving from pop3 server). Using the smpt server from your own ISP is failsafe, though sometimes some other smpt servers will be open for you too.
 
btw, if i weren't such a nice guy I could easily use what I just learned for the most destructive of ends. I can send an email from someone else without their password. Now if I put that into a loop, and got some code to generate random characters...SPAM. I can't believe it is so easy, no wonder there is so much spam out there.
 
Yes spaming would not be hard if you wanted to do it. Unfortuantly, some people do it :(

On the subject of smtp servers, not sure if its much help, but you dont always have to rely on an external server, you can use your own smtp server, such as IIS, and im sure linux has many programs also.

Unfortuantly some people are greedy and spam people :(
 
btw, if i weren't such a nice guy I could easily use what I just learned for the most destructive of ends. I can send an email from someone else without their password. Now if I put that into a loop, and got some code to generate random characters...SPAM. I can't believe it is so easy, no wonder there is so much spam out there.

Emails sent in that way are usually marked by the server, or some upstream server as not being sent by a verified person - there are tricks to detect when this occurs.

Typically organisations will restrict access to an smtp server to only authorised users of its own network. For an ISP, this would be the subscribers of that ISP. Public mail services deny direct access. It is usually not necessary to require authorization for outgoing, as the simple measure of allowing only IP addresses from your own network is effective enough.

When you said that you could access any smtp server from your school - i have my doubts about that. Either your school router runs a redirection whereby any attempt to contact any server on port 25 is re-routed to the school's mail server, or you managed to randomly connect to a few mail servers that would accept the connection and you didnt try submitting an email (at which point the server would return the error "Relay Denied"). Having a server that allows open relay is rather embarassing for any network administrator and it is rather rare that you find them these days.
 
I guess i should say that the first SMTP server I tried worked at my school. I never really tried any others there.
 
Back
Top