System.Web.Mail.Smtp namespace

G

Guest

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(0x80040213): 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 = "(e-mail address removed)" 'From Address
myMessage.To = "(e-mail address removed)" 'To Address
'myMessage.Cc = "(e-mail address removed)" 'Send a Carbon-Copy
'myMessage.Bcc = "(e-mail address removed)" '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
 
C

Carlos J. Quintero [.NET MVP]

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
 
G

Guest

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
 
A

alantolan

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.
 
G

Guest

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
 
G

Guest

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
 
S

Shawn

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: (e-mail address removed)")
buffer = reader.ReadLine
SendCommand("DATA")
buffer = reader.ReadLine
SendCommand("Subject: Lab ERROR")
SendCommand("FROM:" & UserMail)
SendCommand("DATE:" & TheDate)
SendCommand("TO: (e-mail address removed)")
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.ToCharArray)
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
 
C

Chad Z. Hower aka Kudzu

Shawn said:
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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top