473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

System.Web.Mail.Smtp namespace

Trying to send an eMail frommy vb.net App.
Is there anybody out there that has successfully done this?
I am having major problems and need a step by step guide into the world of
system.web and IIS. The reading I have done(alot) has been pretty useless in
helping me understand the various bits required.

The error I get is: On a pc running win2k with IIS and Lotus Notes
System.Runtime.InteropServices.SEHException: External component has thrown
an Exception
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
at System.Web.Mail/SmtpMail.Send(MailMessage message)
at MyAppName.MyFormName.MyMailingFunction

The error I get is: On a DEV(not networked) pc running winXP with with IIS
but without Lotus Notes

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(0x8004 0213): The transport
failed to connect to the server

CODE:::
Imports System.Web.Mail

Private Sub Mail1()
Dim myMessage As New MailMessage
Dim myMailServer As SmtpMail

myMessage.BodyFormat = MailFormat.Text 'or MailFormat.Html
myMessage.Priority = MailPriority.Normal ', High, or Low
myMessage.From = "ma************@quinn-direct.com" 'From Address
myMessage.To = "ma************@quinn-direct.com" 'To Address
'myMessage.Cc = "so*********@somedomain.com" 'Send a Carbon-Copy
'myMessage.Bcc = "so*****@diffdomain.com" 'Send a Blind Carbon-Copy
myMessage.Subject = "VB.NET E-mail Test"
'Below is the Body of the E-mail I did it this way to show that this
property
'can be treated as a string.
myMessage.Body = "This is a test of a Windows E-mailer<BR>" & vbCrLf
myMessage.Body &= "<font color=blue>TEST</font><br>" & vbCrLf & _
"<font color=red>TEST</font><br>" & vbCrLf

'Add an attachment to your Email. Attachments in Windows
applications are touchy.
'In the project it will throw an error if you don’t have the file in
the
'Solution Explorer. But just running the .exe it seems to be fine
with any file.
'Make sure file has full pathing otherwise you will definitely get
an error.
'myMessage.Attachments.Add(New System.Web.Mail.MailAttachment(File))

'10.2.0.4
'cavan02.quinn-direct.com)

'myMailServer.SmtpServer = "cavan02.quinn-direct.com" 'This is your
mail server
myMailServer.SmtpServer = "cn2k-03321.quinn-direct.com" 'This is
your mail server
Try
myMailServer.Send(myMessage)
Catch ex As Exception
MessageBox.Show(ex.ToString)
MessageBox.Show(ex.InnerException.ToString)
MessageBox.Show(ex.Source)
End Try

myMessage = Nothing
End Sub
Nov 21 '05 #1
8 5440
Have you looked at http://systemwebmail.com/ ?

They have a section for troubleshooting...

--
Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
"marcmc" <ma****@discussions.microsoft.com> escribió en el mensaje
news:C9**********************************@microsof t.com...
Trying to send an eMail frommy vb.net App.
Is there anybody out there that has successfully done this?
I am having major problems and need a step by step guide into the world of
system.web and IIS. The reading I have done(alot) has been pretty useless
in
helping me understand the various bits required.

The error I get is: On a pc running win2k with IIS and Lotus Notes
System.Runtime.InteropServices.SEHException: External component has thrown
an Exception
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Web.Mail.CdoSysHelper.Send(MailMessage message)
at System.Web.Mail/SmtpMail.Send(MailMessage message)
at MyAppName.MyFormName.MyMailingFunction

The error I get is: On a DEV(not networked) pc running winXP with with IIS
but without Lotus Notes

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(0x8004 0213): The transport
failed to connect to the server

CODE:::
Imports System.Web.Mail

Private Sub Mail1()
Dim myMessage As New MailMessage
Dim myMailServer As SmtpMail

myMessage.BodyFormat = MailFormat.Text 'or MailFormat.Html
myMessage.Priority = MailPriority.Normal ', High, or Low
myMessage.From = "ma************@quinn-direct.com" 'From Address
myMessage.To = "ma************@quinn-direct.com" 'To Address
'myMessage.Cc = "so*********@somedomain.com" 'Send a Carbon-Copy
'myMessage.Bcc = "so*****@diffdomain.com" 'Send a Blind Carbon-Copy
myMessage.Subject = "VB.NET E-mail Test"
'Below is the Body of the E-mail I did it this way to show that
this
property
'can be treated as a string.
myMessage.Body = "This is a test of a Windows E-mailer<BR>" &
vbCrLf
myMessage.Body &= "<font color=blue>TEST</font><br>" & vbCrLf & _
"<font color=red>TEST</font><br>" & vbCrLf

'Add an attachment to your Email. Attachments in Windows
applications are touchy.
'In the project it will throw an error if you don't have the file
in
the
'Solution Explorer. But just running the .exe it seems to be fine
with any file.
'Make sure file has full pathing otherwise you will definitely get
an error.
'myMessage.Attachments.Add(New
System.Web.Mail.MailAttachment(File))

'10.2.0.4
'cavan02.quinn-direct.com)

'myMailServer.SmtpServer = "cavan02.quinn-direct.com" 'This is your
mail server
myMailServer.SmtpServer = "cn2k-03321.quinn-direct.com" 'This is
your mail server
Try
myMailServer.Send(myMessage)
Catch ex As Exception
MessageBox.Show(ex.ToString)
MessageBox.Show(ex.InnerException.ToString)
MessageBox.Show(ex.Source)
End Try

myMessage = Nothing
End Sub

Nov 21 '05 #2
Thankyou Carlos. You are the first to reply to any of my posts today!

I will look at that resource.
Sending an eMail is actually a second option for me. What I really would
love to do is send a text message(SMS) instead. Have you any references or
personal experience with this?

marc
Nov 21 '05 #3
I got it working but am using MS Exchange / Outlook for mail not
Domino/Notes
....

Dim Message As System.Web.Mail.MailMessage = New
System.Web.Mail.MailMessage
Message.To = txtTo.Text
Message.From = txtFrom.Text
Message.Subject = txtSubject.Text
Message.Body = txtBody.Text

Try

SmtpMail.SmtpServer = txtServer.Text ' Works whether
this is set or not (?)

SmtpMail.Send(Message)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try
NOTES:

Send(), and
SmtpServer

are both Shared members of the SmtpMail class, there is no need to
instantiate myMailServer to use them

As mentioned above, it appears that SmtpServer does not NEED to be set
(at least on WinXP, or Win 2000 Server systems). It works fine for me
wether or not I set it.

Nov 21 '05 #4
Hi Alan
Is the code all you needed to do or did you have work to do with IIS, or the
exchange server.

I'm not so worried about the code, I'll figure that out eventually but any
other factors that need configuration. I'm trying to build a picture of how
this works on a broad level.

VCheers
marc

"al*******@users.com" wrote:
I got it working but am using MS Exchange / Outlook for mail not
Domino/Notes
....

Dim Message As System.Web.Mail.MailMessage = New
System.Web.Mail.MailMessage
Message.To = txtTo.Text
Message.From = txtFrom.Text
Message.Subject = txtSubject.Text
Message.Body = txtBody.Text

Try

SmtpMail.SmtpServer = txtServer.Text ' Works whether
this is set or not (?)

SmtpMail.Send(Message)

Catch ex As Exception

MessageBox.Show(ex.Message)

End Try
NOTES:

Send(), and
SmtpServer

are both Shared members of the SmtpMail class, there is no need to
instantiate myMailServer to use them

As mentioned above, it appears that SmtpServer does not NEED to be set
(at least on WinXP, or Win 2000 Server systems). It works fine for me
wether or not I set it.

Nov 21 '05 #5
When I use Alan's code I get
System.Web.HttpException: Could not access 'CDO.Message' object

I have searched my XP machine and cdonts.dll and cdosys.dll don't seem to
exist

Nov 21 '05 #6
You can use a networkstream, a streamreader and a tcpClient to open a
connection to your smtp server and communicate with it directly. I
don't need to send attachments though so I don't have any experience
with that.

**********************************
'*
'* Shawn Shelton
'* This code will send email using smtp
'* It is currently being used to send mail to me
'* when some portion of code errors.
'*****************************************

Option Explicit On
Option Strict On

Imports System.IO
Imports System.Net
Imports System.Net.Sockets

Module SendError
Dim NetStrm As NetworkStream

Public Sub GenErrMail(ByVal User As String, ByVal RemoteMachine As
String, ByVal Message As String)
Dim localName As String = System.Environment.UserName
Dim UserMail As String = User & "@somewhere.edu"
Dim TheDate As String = GetTime()
Try
Dim reader As StreamReader
Dim buffer As String
Dim SmtpClient As New TcpClient
SmtpClient.Connect("smtpserver.somewhere.edu", 25)
NetStrm = SmtpClient.GetStream()
reader = New StreamReader(SmtpClient.GetStream())
buffer = reader.ReadLine()
SendCommand("HELO " & UserMail)
buffer = reader.ReadLine()
SendCommand("MAIL FROM:" & UserMail)
buffer = reader.ReadLine
SendCommand("RCPT TO: so*****@somewhere.edu")
buffer = reader.ReadLine
SendCommand("DATA")
buffer = reader.ReadLine
SendCommand("Subject: Lab ERROR")
SendCommand("FROM:" & UserMail)
SendCommand("DATE:" & TheDate)
SendCommand("TO: so*****@somewhere.edu")
SendCommand( Message)
SendCommand(vbCrLf)
SendCommand(vbCrLf)
SendCommand(vbCrLf & ".")
buffer = reader.ReadLine
SendCommand("QUIT")
buffer = reader.ReadLine
NetStrm.Close()
reader.Close()
SmtpClient.Close()
buffer = Nothing
Catch ex As Exception
'MsgBox(ex.Message & vbCrLf & ex.Source)
End Try
End Sub

Private Sub SendCommand(ByVal text As String)
Dim szData() As Byte
text = text & vbCrLf
szData = System.Text.Encoding.ASCII.GetBytes(text.ToCharArr ay)
NetStrm.Write(szData, 0, szData.Length)
End Sub

Private Function GetTime() As String
Dim Buffer As String
Buffer = OpenConnection("timeserver.somewhere.edu", 13)
GetTime = FormatDateTime(Buffer)
End Function

Private Function OpenConnection(ByVal server As String, ByVal Port
As Integer) As String
Dim Buffer As String
Dim tcpClient As New System.Net.Sockets.TcpClient
Dim reader As StreamReader
Try
tcpClient.Connect(server, Port)
reader = New StreamReader(tcpClient.GetStream())
Buffer = reader.ReadLine()
reader.Close()
OpenConnection = Buffer
tcpClient.Close()
Catch ex As Exception
OpenConnection = Buffer
End Try
End Function

Public Function FormatDateTime(ByVal NetTime As String) As String
Dim strDate As String
Dim strTime As String
strDate = Trim(Mid(NetTime, 1, 3)) & ", " & Trim(Mid(NetTime,
8, 3)) & " " & Trim(Mid(NetTime, 4, 4)) & " " & Trim(Mid(NetTime, 24,
5))
strTime = Trim(Mid(NetTime, 12, 9)) & " " & "-0700 (MST)"
FormatDateTime = strDate & " " & strTime
End Function

End Module

Nov 21 '05 #7
"Shawn" <Te*********@gmail.com> wrote in news:1120169320.871829.89400
@g43g2000cwa.googlegroups.com:
You can use a networkstream, a streamreader and a tcpClient to open a
connection to your smtp server and communicate with it directly. I
don't need to send attachments though so I don't have any experience
with that.


This is a very bad idea. SMTP base protocol is very simple, but with authenticatino, EHELO, and other
extensions user code is quickly broken.

You can try something like Indy, which is free and implements all of this:
http://www.indyproject.org/
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Make your ASP.NET applications run faster
http://www.atozed.com/IntraWeb/
Nov 21 '05 #8
CDO requires it to be installed, and can have other issues as well. Try a native SMTP example:
http://www.codeproject.com/csharp/IndySMTP.asp
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Develop ASP.NET applications easier and in less time:
http://www.atozed.com/IntraWeb/
Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Eric | last post by:
When I use system.web.mail namespace in most of my integration programs and in windows application programs it doesn't work. it normally gives an exception "Could not access 'CDO.Message' object."...
3
by: Phil Mc | last post by:
Hi has anyone come accross the problem.... with referance to System.Web.Mail.MailMessage and System.Web.Mail.SmtpMail THIS WORKS FINE mail=new MailMessage(); mail.From =...
2
by: hb | last post by:
Hi, Yesterday I applied an automatic Windows security update from Microsoft. Then, none of my web application can send out email using System.Web.Mail.SmtpMail.Send(); I don't see any errors....
5
by: Bryan Martin | last post by:
I have a program which has ran every night fine until last night. Now it bombs with the following errors. I have also broke this down to its simplest form for sending the mail...
4
by: Joe Reiss | last post by:
Hi all, I'm using the System.Net.Mail namespace to set up a SMTP sendmail. This works for the most part, however, when I try to send email to a cell phone text msg. via the Verizon 'vtext'...
1
by: Bob | last post by:
Vs2005 - Framework2. Just to let all of you know. I have found that I can not use an application to send e-mails using the system,net.mail namespace while Outlook express is opened on the same...
2
by: Alex Maghen | last post by:
I want to use the new System.Net.Mail instead of the old System.Web.Mail. I'm getting an error "Hot not specified" when I try to do my last two lines: System.Net.Mail.SmtpClient SMTP = new...
3
by: Fetty | last post by:
I need to send the email with an email address that is not in my domain, but it will not do that. Can this be done
12
by: kimiraikkonen | last post by:
Hello, I'm trying to create a basic SMTP mail sender using that code, i'm using VB.NET 2005 "express" but this namespace wasn't recognized... (system.web.MAIL) I'm only allowed to declare under...
11
by: Ed Bitzer | last post by:
I have been able using the namespace System.Web.Mail and its method Smtp.mail.send to mail simple text messages to a small group within our 55 and older community. I need help expanding the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.