12 Replies - 21723 Views - Last Post: 18 August 2012 - 06:04 PM Rate Topic: -----

#1 musicmaniac123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-June 08

How to receive email's

Posted 28 July 2008 - 01:09 PM

hello. im working on an application that is sort of like outlook. You will be able to set up your email account (from a internet email like gmail or aol) and it will grab the email the internet mail. I have the sending part taken care of but i need the reveiving part. If anyone would be able to help me code something to recieve email from a internet website such as gmail or aol, i would be very thankful. Because of the dream in code's policy, i will show you what i have so far. I probably should say that i am using visual basics 2008.

heres the code for sending email...

Imports System.Net.Mail
Public Class Form1

Public Sub SendEmail()
Dim client As New SmtpClient()
Dim sendTo As New MailAddress("SendingTo@gmail.com")
Dim from As MailAddress = New MailAddress("SentFrom@gmail.com")
Dim message As New MailMessage(from, sendTo)
message.IsBodyHtml = True
message.Subject = "The Subject"
message.Body = "Message's Body"

Dim basicAuthenticationInfo As New System.Net.NetworkCredential("your username", "your password")
 
client.Host = "smtp.gmail.com"
client.UseDefaultCredentials = False
client.Credentials = basicAuthenticationInfo
client.EnableSsl = True
Try
client.Send(message)
msgbox"Message Sent!"
Catch ex As Exception
msgbox"Message not sent."
End Try
End Sub



This works great. I just need the reveive email part.
Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: How to receive email's

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How to receive email's

Posted 28 July 2008 - 03:14 PM

Moved to VB.NET :)
Was This Post Helpful? 0
  • +
  • -

#3 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

Re: How to receive email's

Posted 28 July 2008 - 05:23 PM

well i found something in an arabic site about this but i didn't try it yet
ok i will translate
first u have to get a gmail to be able to send with it cuz it have smtp
second type these
imports system.net.mail
imports system.net.mail.mailmessage
imports system.net.networkcredential

then u type the code
dim mail as new mailmessage
dim smtp as new smtpclient
mail.form=new mailadress("'your gmail account'","'your name or something'")
mail.to.add("'mail u want the message to be sent to'")
mail.subject="'subject'"
mail.body="the message u want to send'"
mail.isbodyhtml=true'u can disable it if u don't want the mail to contain html'
mail.reply to=new mailadree("'i gues there is something wrong in this code'")
'this part i am not sure of it but u can try'
smtp.host="smtp.gmail.com"
smtp.port=25
smtp.enable ssl=true
smtp.credentials=new system.net.networkcredential("'your email'","'your email password'"'or the opposit i think')
smtp.send('mail')
msgbox("your message has been sent")

or a short way

dim smtp as new net.mail.smtpclient("'smtp.domail.com'")
dim msg as new net.mail.mailmessage('this area contains your email,the email u want to be sent to ,subject,messaege and don't worry cuz the vb.net will tell u what are they and u will have to leave a comma between each')
smtp.send('msg')


and here is an explanation
smtp.domain.com=smtp server adress


and of course lots of things will be replaced by textboxes

hey wait it is working well with u?
so u want the part so u will recieve mail from ur project?
i have no idea about that
but i am glad u made this topic,i was going to make one soon cuz my code wasb't working well
i hope this was helpful
Was This Post Helpful? 0
  • +
  • -

#4 musicmaniac123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-June 08

Re: How to receive email's

Posted 28 July 2008 - 06:21 PM

I want it so that it will be able to take the mail that you received from a different person. It will show up in your form. When you double click on it, you will be able to open it. just like outlook, or gmail, or aim. And yea. i was looking for the receive part. Thanks though. And actually, my send mail part works great. All you need is a button or something ( you could even add it in the sendemail() part after "Try" . you would have me.sendmail and it works just fine. If you can figure out how to receive mail, please tell me. Thanks a lot!
Was This Post Helpful? 0
  • +
  • -

#5 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

Re: How to receive email's

Posted 28 July 2008 - 07:08 PM

well i don't think i can help u with this cuz the code u gave didn't work for me and i see the message"message not sent"
so what is wrong?
may be it is something in this area
client.Host = "smtp.gmail.com"
what should be typed there then?
Was This Post Helpful? 0
  • +
  • -

#6 musicmaniac123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-June 08

Re: How to receive email's

Posted 28 July 2008 - 07:26 PM

i think i know what you need to do.
everything is alright with the "smtp.gmail.com"
you just need to add @gmail.com to your username
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("YourGmailUsername@gmail.com", "xxxxxxxxx your password")

i think everything should be fine then.
if not, ill try something else then.
Was This Post Helpful? 0
  • +
  • -

#7 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

Re: How to receive email's

Posted 28 July 2008 - 07:48 PM

well the final code is this
Imports System.Net.Mail
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim client As New SmtpClient()
        Dim sendTo As New MailAddress("mbkfa93@gmail.com")
        Dim from As MailAddress = New MailAddress("mbkfa93@gmail.com")
        Dim message As New MailMessage("mbkfa93@gmail.com", "mbkfa93@gmail.com")
        message.IsBodyHtml = True
        message.Subject = "subject"
        message.Body = Me.TextBox1.Text
        Dim basicAuthenticationInfo As New System.Net.NetworkCredential("mbkfa93@gmail.com", "my email password")

        client.Host = "smtp.gmail.com"
        client.UseDefaultCredentials = False
        client.Credentials = basicAuthenticationInfo
        client.EnableSsl = True
        Try
            client.Send(message)
            MsgBox("Message Sent!")
        Catch ex As Exception
            MsgBox("Message not sent.")
        End Try

    End Sub
End Class


and now i still get the "message not sent message"
what is the problem now then?
Was This Post Helpful? 0
  • +
  • -

#8 musicmaniac123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 28-June 08

Re: How to receive email's

Posted 28 July 2008 - 08:03 PM

Imports System.Net.Mail
Public Class Form1
	Public Sub SendEmail()
		Dim client As New SmtpClient()
		Dim sendTo As New MailAddress("musicmaniac108@gmail.com")
		Dim from As MailAddress = New MailAddress("musicmaniac108@gmail.com")
		Dim message As New MailMessage(from, sendTo)
		message.IsBodyHtml = True
		message.Subject = "The Subject"
		message.Body = TextBox1.Text

		Dim basicAuthenticationInfo As New System.Net.NetworkCredential("musicmaniac108@gmail.com", "passwrd")

		client.Host = "smtp.gmail.com"
		client.UseDefaultCredentials = False
		client.Credentials = basicAuthenticationInfo
		client.EnableSsl = True
		Try
			client.Send(message)
			MsgBox("Message Sent")
		Catch ex As Exception
			MsgBox("Message not sent.")
		End Try
	End Sub

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Me.SendEmail()
	End Sub
end class




dont change anything except your username and the email stuff. the ovbious. lol
reply and tell me if it works
Was This Post Helpful? 0
  • +
  • -

#9 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: How to receive email's

Posted 28 July 2008 - 09:46 PM

I'm sorry to say that the .Mail namespace can only be used for sending emails, not receiving.

You will need to look into using Microsoft.Office.Interrop.Outlook Namespace.

However, perhaps this link will provide you with what you need.
Was This Post Helpful? 0
  • +
  • -

#10 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: How to receive email's

Posted 28 July 2008 - 10:44 PM

You will need to look into using the TcpClient() class of the System.Net.Sockets class. Here is some sample code that should at least get you down the right path:


Dim tcpC As New System.Net.Sockets.TcpClient()

    ' send command strings and return the response
    Function SendCommand(ByRef netstream As System.Net.Sockets.NetworkStream, ByVal sToSend As String)
        Dim bData() As Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray)
        netstream.Write(bData, 0, bData.Length())
        Return GetResponse(netstream)
    End Function

    ' check if there is a response to get and return it
    Function GetResponse(ByRef netstream As System.Net.Sockets.NetworkStream)
        Dim bytes(tcpC.ReceiveBufferSize) As Byte
        Dim ret As Integer = netstream.Read(bytes, 0, bytes.Length)
        ' Returns the data received 
        Dim returndata As String = Encoding.ASCII.GetString(bytes)
        Return returndata
    End Function



    Function ReadMail(ByVal host As String, ByVal user As String, ByVal pass As String)
        ' initialise objects	
        Dim netstream As System.Net.Sockets.NetworkStream
        Dim thisResponse As String

        ' open connection to server
        Try
            tcpC.Connect(host, 110)
        Catch ex As Exception
            Response.Write("Error connecting to host: " & ex.Message & " - Please check your details and try again")
            Response.End()
        End Try

        ' get response
        netstream = tcpC.GetStream()
        thisResponse = GetResponse(netstream)

        ' enter user name
        thisResponse = SendCommand(netstream, "user " & user & vbCrLf)

        ' enter password
        thisResponse = SendCommand(netstream, "pass " & pass & vbCrLf)

        ' check if logged in ok
        If Not Left(thisResponse, 4) = "-ERR" Then
            Response.Write("<font face=courier>Logged in OK <BR>")
        Else
            Response.Write("Error logging in, check your user details and try again<BR>")
            Response.Write("<P>" & thisResponse)
            Response.End()
        End If

        thisResponse = SendCommand(netstream, "stat" & vbCrLf)

        Dim tmpArray() As String
        tmpArray = Split(thisResponse, " ")

        Dim thisMess As Integer
        Dim numMess As String = tmpArray(1)

        Response.Write("<p><hr>")

        thisResponse = ""

        If CInt(numMess) > 0 Then
            Response.Write("Messages: " & numMess & "<br>")
            For thisMess = 1 To CInt(numMess)
                thisResponse += Replace(SendCommand(netstream, "top " &  _
                thisMess & " 10" & vbCrLf), vbCrLf, "<br>")
            Next
        Else
            Response.Write("Messages: None" & "<br>")
        End If

        thisResponse += Replace(SendCommand(netstream, "stat" & vbCrLf),  _
                                   vbCrLf, "<br>")

        tmpArray = Split(thisResponse, "+OK")

        Response.Write(thisResponse)

        Dim msg As Integer
        For msg = 1 To tmpArray.Length - 1
            Response.Write("<h3>#" & msg & "</h1>" & tmpArray(msg) & "<p>")
        Next

        ' close connection
        thisResponse = SendCommand(netstream, "QUIT" & vbCrLf)
        tcpC.Close()
    End Function




Hope that helps you some, and gets you down the right path :)
Was This Post Helpful? 0
  • +
  • -

#11 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

Re: How to receive email's

Posted 29 July 2008 - 09:59 AM

i did as u said musicmania and here is my final code but still the same trouble,message not sent
Imports System.Net.Mail
Public Class Form1
    Public Sub SendEmail()
        Dim client As New SmtpClient()
        Dim sendTo As New MailAddress("mbkfa93@gmail.com", "meena")
        Dim from As MailAddress = New MailAddress("mbkfa93@gmail.com")
        Dim message As New MailMessage(from, sendTo)
        message.IsBodyHtml = True
        message.Subject = "The Subject"
        message.Body = TextBox1.Text

        Dim basicAuthenticationInfo As New System.Net.NetworkCredential("mbkfa93@gmail.com", "my password")

        client.Host = "smtp.gmail.com"
        client.UseDefaultCredentials = False
        client.Credentials = basicAuthenticationInfo
        client.EnableSsl = True
        Try
            client.Send(message)
            MsgBox("Message Sent")
        Catch ex As Exception
            MsgBox("Message not sent.")
        End Try
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.SendEmail()
    End Sub
End Class


and if u want to make the code vb use
code=vb instead of code
and they both end with /code
Was This Post Helpful? 1

#12 makulitz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-June 12

Re: How to receive email's

Posted 15 June 2012 - 12:21 AM

try to read a pop3 commands it will help you to know how to receive message using your email account
Was This Post Helpful? 0
  • +
  • -

#13 evry1falls  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 44
  • Joined: 25-April 12

Re: How to receive email's

Posted 18 August 2012 - 06:04 PM

You can try this one to receive E-mails :
http://evry1falls.fr.../vbnetpop4.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1