Send Email in CF

G

Guest

I am looking for info on how to send email in the CF.

I looked at mooseworks but I am assigning the outgoing server name and it didn't seem to allow that. (Uses outlook
IPWorks is $600!!

Any other suggestions??
 
F

Felipe T.

Yeah...Other Suggestion;
I found this class somewhere, and i kept it for future uses. It works very
well using sockets and SMTP. Mayb it can help ya.

'=======================================================
Imports System.IO
Imports System.Net.Sockets
Imports System.Text

Public Class SocketMail
Private _subject As String
Private _to As String
Private _server As String
Private _port As Integer = 25
Private _body As String
Private _date As Date = Now
Private _from As String
Private _cc As String
Private _bcc As String

Private ns As NetworkStream
Private client As New TcpClient

Public Sub New()
End Sub

Public Sub New(ByVal server As String, ByVal port As Integer)
_server = server
_port = port
End Sub

Public Sub New(ByVal server As String, ByVal port As Integer, _
ByVal from As String, ByVal [to] As String, _
ByVal subject As String, ByVal message As String)
_server = server
_port = port
_from = from
_to = [to]
_subject = subject
_body = message
End Sub

Public Property SMTPServer() As String
Get
Return _server
End Get
Set(ByVal Value As String)
_server = Value
End Set
End Property

Public Property [To]() As String
Get
Return _to
End Get
Set(ByVal Value As String)
_to = Value
End Set
End Property

Public Property From() As String
Get
Return _from
End Get
Set(ByVal Value As String)
_from = Value
End Set
End Property

Public Property CarbonCopy() As String
Get
Return _cc
End Get
Set(ByVal Value As String)
_cc = Value
End Set
End Property

Public Property BlindCarbonCopy() As String
Get
Return _bcc
End Get
Set(ByVal Value As String)
_bcc = Value
End Set
End Property


Public Property Port() As Integer
Get
Return _port
End Get
Set(ByVal Value As Integer)
_port = Value
End Set
End Property

Public Property Message() As String
Get
Return _body
End Get
Set(ByVal Value As String)
_body = Value
End Set
End Property

Public Property SendDate() As Date
Get
Return _date
End Get
Set(ByVal Value As Date)
_date = Value
End Set
End Property

Public Property Subject() As String
Get
Return _subject
End Get
Set(ByVal Value As String)
_subject = Value
End Set
End Property

Public Function Open()
client.Connect(_server, _port)

ns = client.GetStream()

Dim strMessage As String = "HELO TEST" & ControlChars.CrLf

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage)
ns.Write(sendBytes, 0, sendBytes.Length)
End Function

Public Function Close()
Try
Dim strMessage As String = "QUIT" & ControlChars.CrLf

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage)
ns.Write(sendBytes, 0, sendBytes.Length)
Catch

End Try

client.Close()
End Function

Public Function Send() As Boolean
Try
Dim response As Integer
Dim strMessage As String

strMessage = "MAIL FROM:" & _from & ControlChars.CrLf & _
"RCPT TO:" & _to & ControlChars.CrLf & _
"DATA" & ControlChars.CrLf & _
"date:" & _date.ToString & ControlChars.CrLf & _
"from:" & _from & ControlChars.CrLf & _
"to:" & _to & ControlChars.CrLf & _
"cc:" & _cc & ControlChars.CrLf & _
"bcc:" & _bcc & ControlChars.CrLf & _
"subject:" & _subject & ControlChars.CrLf & _
_body & ControlChars.CrLf & _
"." & ControlChars.CrLf

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage)
ns.Write(sendBytes, 0, sendBytes.Length)
Finally
client.Close()
End Try

Return True
End Function

End Class
'=======================================================

'Use the class this way:
'Test making a Form and put in a button..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim mMail As New SocketMail("123.125.251.21", 25)

With mMail
.To = "(e-mail address removed)"
.From = "(e-mail address removed)"
.Subject = "E-Mail Title"
.Message = "Hallo Word"
.Open()
.Send()
.Close()
End With

End Sub
'=======================================================


----- Original Message -----
From: "Aaron" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
Sent: Friday, February 13, 2004 2:11 PM
Subject: Send Email in CF

I am looking for info on how to send email in the CF.

I looked at mooseworks but I am assigning the outgoing server name and it
didn't seem to allow that. (Uses outlook)
 
F

Felipe T.

Take a look at:

http://groups.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&oe=UTF-8&threadm=l
uw5gg6tok3y.piq9o5hiafpu.dlg%4040tude.net&rnum=3&prev=/groups%3Fq%3DAttachme
nt%2Bgroup:microsoft.public.dotnet.framework.compactframework%26hl%3Den%26lr
%3Dlang_en%26ie%3DUTF-8%26oe%3DUTF-8%26group%3Dmicrosoft.public.dotnet.frame
work.compactframework%26selm%3Dluw5gg6tok3y.piq9o5hiafpu.dlg%254040tude.net%
26rnum%3D3


Aaron said:
Excellent, any clue how to add an attachment???

----- Felipe T. wrote: -----

Yeah...Other Suggestion;
I found this class somewhere, and i kept it for future uses. It works very
well using sockets and SMTP. Mayb it can help ya.

'=======================================================
Imports System.IO
Imports System.Net.Sockets
Imports System.Text

Public Class SocketMail
Private _subject As String
Private _to As String
Private _server As String
Private _port As Integer = 25
Private _body As String
Private _date As Date = Now
Private _from As String
Private _cc As String
Private _bcc As String

Private ns As NetworkStream
Private client As New TcpClient

Public Sub New()
End Sub

Public Sub New(ByVal server As String, ByVal port As Integer)
_server = server
_port = port
End Sub

Public Sub New(ByVal server As String, ByVal port As Integer, _
ByVal from As String, ByVal [to] As String, _
ByVal subject As String, ByVal message As String)
_server = server
_port = port
_from = from
_to = [to]
_subject = subject
_body = message
End Sub

Public Property SMTPServer() As String
Get
Return _server
End Get
Set(ByVal Value As String)
_server = Value
End Set
End Property

Public Property [To]() As String
Get
Return _to
End Get
Set(ByVal Value As String)
_to = Value
End Set
End Property

Public Property From() As String
Get
Return _from
End Get
Set(ByVal Value As String)
_from = Value
End Set
End Property

Public Property CarbonCopy() As String
Get
Return _cc
End Get
Set(ByVal Value As String)
_cc = Value
End Set
End Property

Public Property BlindCarbonCopy() As String
Get
Return _bcc
End Get
Set(ByVal Value As String)
_bcc = Value
End Set
End Property


Public Property Port() As Integer
Get
Return _port
End Get
Set(ByVal Value As Integer)
_port = Value
End Set
End Property

Public Property Message() As String
Get
Return _body
End Get
Set(ByVal Value As String)
_body = Value
End Set
End Property

Public Property SendDate() As Date
Get
Return _date
End Get
Set(ByVal Value As Date)
_date = Value
End Set
End Property

Public Property Subject() As String
Get
Return _subject
End Get
Set(ByVal Value As String)
_subject = Value
End Set
End Property

Public Function Open()
client.Connect(_server, _port)

ns = client.GetStream()

Dim strMessage As String = "HELO TEST" & ControlChars.CrLf

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage)
ns.Write(sendBytes, 0, sendBytes.Length)
End Function

Public Function Close()
Try
Dim strMessage As String = "QUIT" & ControlChars.CrLf

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage)
ns.Write(sendBytes, 0, sendBytes.Length)
Catch

End Try

client.Close()
End Function

Public Function Send() As Boolean
Try
Dim response As Integer
Dim strMessage As String

strMessage = "MAIL FROM:" & _from & ControlChars.CrLf & _
"RCPT TO:" & _to & ControlChars.CrLf & _
"DATA" & ControlChars.CrLf & _
"date:" & _date.ToString & ControlChars.CrLf & _
"from:" & _from & ControlChars.CrLf & _
"to:" & _to & ControlChars.CrLf & _
"cc:" & _cc & ControlChars.CrLf & _
"bcc:" & _bcc & ControlChars.CrLf & _
"subject:" & _subject & ControlChars.CrLf & _
_body & ControlChars.CrLf & _
"." & ControlChars.CrLf

Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(strMessage)
ns.Write(sendBytes, 0, sendBytes.Length)
Finally
client.Close()
End Try

Return True
End Function

End Class
'=======================================================

'Use the class this way:
'Test making a Form and put in a button..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim mMail As New SocketMail("123.125.251.21", 25)

With mMail
.To = "(e-mail address removed)"
.From = "(e-mail address removed)"
.Subject = "E-Mail Title"
.Message = "Hallo Word"
.Open()
.Send()
.Close()
End With

End Sub
'=======================================================


----- Original Message -----
From: "Aaron" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
Sent: Friday, February 13, 2004 2:11 PM
Subject: Send Email in CF

I am looking for info on how to send email in the CF.
and it
didn't seem to allow that. (Uses outlook)
IPWorks is $600!!!
 

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