使用此代码概念接收电子邮件 [英] Receive email with this code concept

查看:132
本文介绍了使用此代码概念接收电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我有此代码发送电子邮件:



Hi
I have this code to send emails:

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





但是你怎么能收到一个定时器节拍的电子邮件,比方说,间隔为10秒文本框?

(如果可能的话,我想要一个类似上面的代码,这就是Outlook在发送/接收按钮上点击的内容)



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)

推荐答案

你好Rixterz123



你会发现这些文章很有帮助。

Hello Rixterz123

You will find these articles helpful.

  • POP3 Client as a C# Class[^]
  • Retrieving Mail with POP3[^]


这篇关于使用此代码概念接收电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆