Simple mail application

  • Thread starter Thread starter Sehboo
  • Start date Start date
S

Sehboo

Hi,

I want to write a very very simple mail application which my father can
use (maybe then I will be able to send and receive emails from him).
This application will have a text box, where he will type a message,
and a button. Once he presses this button the application will send an
email to me (my email address will be hardcoded). I don't think that
it can get any simpler.

Problem is that how to send email from standalone machine with just
internet connection? He, of course doesn't have any SMTP server or any
thing like that on his machine. So is it even possible? It can't be
that hard. Can anybody pass me a code that sends email just by using
internet connection?

Thanks
 
Check out 'System.Web.Mail' namespace

One thing though: SPAM filter could catch these types of messages & you may
have to apply to go on a white list because they think you are SPAMMING

Crouchie1998
BA (HONS) MCP MCSE
 
I have signed him up...but he wants to use something simple - very
simple.

Also, all of those example codes require SMTP server. Like I said, he
doesn't have SMTP server. He is on WinXP with internet connection. I
hope it is possible to just send an email without any server.
 
while it is in theory possible to have him connect directly (via your
program) to your SMTP server (i.e. the server that processes your
email), I am not sure that this is your esiest approach (the command
that you will need to send are here
http://www.faqs.org/rfcs/rfc821.html)

he WILL need to connect to a server to send mail -- there is no way
around this (this is how mail gets sent).

there is a c# sample of how to write a simple client here:
http://www.csharphelp.com/archives/archive122.html

Cheers.
 

Using the above plus the tcpClient help in VS I contructed this. I am sure
it can be improved (quick attempt) and there is no validation on the return
strings:

Tested and works:

Imports System.Net.Sockets
Imports System.Text

Dim tcpClient As New TcpClient()
Try
tcpClient.Connect("mail.btopenworld.com", 25)
Dim networkStream As NetworkStream = tcpClient.GetStream()

If networkStream.CanWrite And networkStream.CanRead Then

' HELO
' Does a simple write.
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("HELO
<yourdomain.com>" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)

' Reads the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0,
CInt(tcpClient.ReceiveBufferSize))

' Returns the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
MsgBox((returndata))

' MAIL FROM
sendBytes = Encoding.ASCII.GetBytes("MAIL
FROM:<[email protected]>" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes2(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes2, 0,
CInt(tcpClient.ReceiveBufferSize))
returndata = Encoding.ASCII.GetString(bytes2)
MsgBox((returndata))

' RCPT TO
sendBytes = Encoding.ASCII.GetBytes("RCPT
TO:<[email protected]>" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes3(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes3, 0,
CInt(tcpClient.ReceiveBufferSize))
returndata = Encoding.ASCII.GetString(bytes3)
MsgBox((returndata))

' DATA
sendBytes = Encoding.ASCII.GetBytes("DATA" & vbCrLf)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes4(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes4, 0,
CInt(tcpClient.ReceiveBufferSize))
returndata = Encoding.ASCII.GetString(bytes4)
MsgBox((returndata))

' Finally the message
Dim txtData As String = _
"Date: 15 May 2005 11:00:00" & vbCrLf & _
"From: (e-mail address removed)" & vbCrLf & _
"To: (e-mail address removed)" & vbCrLf & _
"Subject: This is a test message" & vbCrLf & vbCrLf & _
"This is the body of the message" & vbCrLf & "." & vbCrLf

'Message
sendBytes = Encoding.ASCII.GetBytes(txtData)
networkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes5(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes5, 0,
CInt(tcpClient.ReceiveBufferSize))
returndata = Encoding.ASCII.GetString(bytes5)
MsgBox((returndata))

' Close connection
tcpClient.Close()

Else
If Not networkStream.CanRead Then
MsgBox("You can not write data to this stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
MsgBox("You can not read data from this stream")
tcpClient.Close()
End If
End If
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
 
Sehboo said:
Hi,

I want to write a very very simple mail application which my father can
use (maybe then I will be able to send and receive emails from him).
This application will have a text box, where he will type a message,
and a button. Once he presses this button the application will send an
email to me (my email address will be hardcoded). I don't think that
it can get any simpler.

Problem is that how to send email from standalone machine with just
internet connection? He, of course doesn't have any SMTP server or any
thing like that on his machine. So is it even possible? It can't be
that hard. Can anybody pass me a code that sends email just by using
internet connection?

Thanks

If he has got an Internet connection then this must be via an ISP. I
don't know of any ISP that does not offer email services. So why not use
CDO to connect to their SMTP server to send the emails.

1.. Store his outgoing emails in your our little database.
2.. Connect via CDO to his ISP's SMTP server to send them.
3.. Connect via CDO to his POP account to download your emails.

Kind Regards,
 
Sehboo said:
I have signed him up...but he wants to use something simple - very
simple.

Also, all of those example codes require SMTP server. Like I said, he
doesn't have SMTP server. He is on WinXP with internet connection. I
hope it is possible to just send an email without any server.

His ISP doesn't provide email to him? If they do, he's already got access to
an SMTP server that your program can talk to.
 
internet connection? He, of course doesn't have any SMTP server or
connection?

He does not need his own SMTP server. He can send it directly to
the SMTP server of the recipient, so if you're hard coding your email address
you can also hard-code your SMTP server. If you want him to be able to change
the recipient email address, then you'll need code to look up the MX record of
the domain to determine the mail server to send to. There are several solutions
to this if you do not know how, including IPWorks MX
component.

Regards,
Lance R.
/n software
http://www.nsoftware.com/

-
 
He does not need his own SMTP server. He can send it directly to
the SMTP server of the recipient, so if you're hard coding your email address
you can also hard-code your SMTP server. If you want him to be able to change
the recipient email address, then you'll need code to look up the MX record of
the domain to determine the mail server to send to. There are several solutions
to this if you do not know how, including IPWorks MX
component.



This may well not work. Many servers now block direct to MX mailings,
mailings from addresses without proper reverse lookup entries and mailings
from systems found in dynamic address pools.
 

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

Back
Top