Click here to Skip to main content
15,923,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have this code to send emails:

VB
Imports System.Net.Mail
Public Class Form1
    Function SendEmail(ByVal Recipients As List(Of String), ByVal FromAddress As String, ByVal Subject As String, ByVal Body As String, ByVal UserName As String, ByVal Password As String, Optional ByVal Server As String = "smtp.gmail.com", Optional ByVal Port As Integer = 587, Optional ByVal Attachments As List(Of String) = Nothing) As String
        Dim Email As New MailMessage()
        Try
            Dim SMTPServer As New SmtpClient
            For Each Attachment As String In Attachments
                Email.Attachments.Add(New Attachment(Attachment))
            Next
            Email.From = New MailAddress(FromAddress)
            For Each Recipient As String In Recipients
                Email.To.Add(Recipient)
            Next
            Email.Subject = Subject
            Email.Body = Body
            SMTPServer.Host = Server
            SMTPServer.Port = Port
            SMTPServer.Credentials = New System.Net.NetworkCredential(UserName, Password)
            SMTPServer.EnableSsl = True
            SMTPServer.Send(Email)
            Email.Dispose()
            Return "Email sent."
        Catch ex As SmtpException
            Email.Dispose()
            Return "Sending Email Failed. Smtp Error."
        Catch ex As ArgumentOutOfRangeException
            Email.Dispose()
            Return "Sending Email Failed. Check Port Number."
        Catch Ex As InvalidOperationException
            Email.Dispose()
            Return "Sending Email Failed. Check Port Number."
        End Try
    End Function
    Private Sub SendBtn_Click() Handles SendBtn.Click
        Dim Recipients As New List(Of String)
        Recipients.Add("SomeEmailAddress") 
        Dim FromEmailAddress As String = Recipients(0)
        Dim Subject As String = "Test From VB." 
        Dim Body As String = "email body text." 
        Dim UserName As String = "GMAIL USERNAME WITHOUT  (@GMAIL>COM)" 
        Dim Password As String = "Password" 
        Dim Port As Integer = 587
        Dim Server As String = "smtp.gmail.com"
        Dim Attachments As New List(Of String)
        MsgBox(SendEmail(Recipients, FromEmailAddress, Subject, Body, UserName, Password, Server, Port, Attachments))
    End Sub
End Class


But how can you receive emails on a timer tick of, say, 10 second intervals into a textbox?
(I would like a code similar to the one above if possible, and this is what Outlook does on the Send/Receive button click)
Posted
Comments
Sandeep Mewara 11-Apr-13 13:24pm    
And what have you tried so far for what you need?

1 solution

Hello Rixterz123

You will find these articles helpful.

Note : Just do a search on CP. Here you can find wealth of information,

Regards,
 
Share this answer
 
Comments
[no name] 13-Apr-13 8:03am    
Do you know of a VB.Net version?
Prasad Khandekar 13-Apr-13 8:42am    
http://www.codeproject.com/Articles/18008/Simple-POP3-Email-Class
[no name] 13-Apr-13 11:37am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900