vb.net读取邮件标题 vb发送邮件
要一段VB.NET发邮件的代码
'创建发件连接,根据你的发送邮箱的SMTP设置填充
专注于为中小企业提供成都做网站、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业嘉黎免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了1000+企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。
Dim smtp As New System.Net.Mail.SmtpClient("smtp.163.com", 25)
'发件邮箱身份验证,参数分别为 发件邮箱登录名和密码
smtp.Credentials = New System.Net.NetworkCredential("用户名", "密码")
'创建邮件
Dim mail As New System.Net.Mail.MailMessage()
'邮件主题
mail.Subject = "邮件主题"
'主题编码
mail.SubjectEncoding = System.Text.Encoding.GetEncoding("GB2312")
'邮件正文件编码
mail.BodyEncoding = System.Text.Encoding.GetEncoding("GB2312")
'发件人邮箱
mail.From = New System.Net.Mail.MailAddress("example@163.com")
'邮件优先级
mail.Priority = System.Net.Mail.MailPriority.Normal
'HTML格式的邮件,为false则发送纯文本邮箱
mail.IsBodyHtml = True
'邮件内容
mail.Body = "邮件正文内容"
'添加收件人,如果有多个,可以多次添加
mail.To.Add("收件人地址")
'定义附件,参数为附件文件名,包含路径,推荐使用绝对路径
'如果不需要附件,下面三行可以不要
Dim a As New System.Net.Mail.Attachment("附件文件")
'附件文件名,用于收件人收到附件时显示的名称
a.Name = "附件文件名"
'加入附件,可以多次添加
mail.Attachments.Add(a)
'发送邮件
Try
smtp.Send(mail)
MessageBox.Show("发送成功")
Catch
MessageBox.Show("发送失败")
Finally
mail.Dispose()
End Try
vba读取邮件标题
试试下面的代码:
Sub 导入邮件()
On Error Resume Next
Dim olApp As New Outlook.Application, olNameSpace As Outlook.Namespace
Dim olMailItem As Outlook.MailItem, olFolder As Outlook.Folder
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olFolder = olNameSpace.GetDefaultFolder(olFolderInbox) '收件箱
For i = 1 To olFolder.Items.Count
Set olMailItem = olFolder.Items(i) '获取一个邮件项目
With olMailItem
ActiveSheet.Cells(i + 2, 1) = IIf(.UnRead, "未读", "已读") '状态
ActiveSheet.Cells(i + 2, 2) = .SenderName "(" .SenderEmailAddress ")" '发件人
ActiveSheet.Cells(i + 2, 3) = .Subject '主题
ActiveSheet.Cells(i + 2, 4) = .ReceivedTime '主题
End With
Next
End Sub
VB.NET如何获取任何格式文件的文字信息
Option Explicit
'mTextUTF.bas
'模块:UTF文本文件访问
'作者:zyl910
'版本:1.0
'日期:2006-1-23
'== 说明 ===================================================
'支持Unicode编码的文本文件读写。暂时支持ANSI、UTF-8、UTF-16LE、UTF-16BE这几种编码文本
'== 更新记录 ===============================================
'[V1.0] 2006-1-23
'1.支持最常见的ANSI、UTF-8、UTF-16LE、UTF-16BE这几种编码文本
'## 编译预处理常数 #########################################
'== 全局常数 ===============================================
'IncludeAPILib:引用了API库,此时不需要手动写API声明
'## API ####################################################
#If IncludeAPILib = 0 Then
'== File ===================================================
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Declare Function SetFilePointer Lib "kernel32" (ByVal hFile As Long, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Private Const INVALID_HANDLE_VALUE = -1
Private Const GENERIC_READ = H80000000
Private Const GENERIC_WRITE = H40000000
Private Const FILE_SHARE_READ = H1
Private Const FILE_SHARE_WRITE = H2
Private Const Create_NEW = 1
Private Const Create_ALWAYS = 2
Private Const OPEN_EXISTING = 3
Private Const OPEN_ALWAYS = 4
Private Const TRUNCATE_EXISTING = 5
Private Const FILE_ATTRIBUTE_NORMAL = H80
Private Const FILE_BEGIN = 0
Private Const FILE_CURRENT = 1
Private Const FILE_END = 2
'== Unicode ================================================
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByRef lpWideCharStr As Any, ByVal cchWideChar As Long) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByRef lpWideCharStr As Any, ByVal cchWideChar As Long, ByRef lpMultiByteStr As Any, ByVal cchMultiByte As Long, ByRef lpDefaultChar As Any, ByVal lpUsedDefaultChar As Long) As Long
Private Const CP_UTF8 As Long = 65001
#End If
'###########################################################
'Unicode编码格式
Public Enum UnicodeEncodeFormat
UEF_ANSI = 0 'ANSI+DBCS
UEF_UTF8 'UTF-8
UEF_UTF16LE 'UTF-16LE
UEF_UTF16BE 'UTF-16BE
UEF_UTF32LE 'UTF-32LE
UEF_UTF32BE 'UTF-32BE
UEF_Auto = -1 '自动识别编码
'隐藏项目
[_UEF_Min] = UEF_ANSI
[_UEF_Max] = UEF_UTF32BE
End Enum
'ANSI+DBCS方式的文本所使用的代码页。默认为0,表示使用系统当前代码页。可以利用该参数实现读取其他代码编码的文本,比如想在 简体中文平台下 读取 繁体中文平台生成的txt,就将它设为950
Public UEFCodePage As Long
'判断BOM
'返回值:BOM所占字节
'dwFirst:[in]文件最开始的4个字节
'fmt:[out]返回编码类型
Public Function UEFCheckBOM(ByVal dwFirst As Long, ByRef fmt As UnicodeEncodeFormat) As Long
If dwFirst = HFEFF Then
fmt = UEF_UTF32LE
UEFCheckBOM = 4
ElseIf dwFirst = HFFFE0000 Then
fmt = UEF_UTF32BE
UEFCheckBOM = 4
ElseIf (dwFirst And HFFFF) = HFEFF Then
fmt = UEF_UTF16LE
UEFCheckBOM = 2
ElseIf (dwFirst And HFFFF) = HFFFE Then
fmt = UEF_UTF16BE
UEFCheckBOM = 2
ElseIf (dwFirst And HFFFFFF) = HBFBBEF Then
fmt = UEF_UTF8
UEFCheckBOM = 3
Else
fmt = UEF_ANSI
UEFCheckBOM = 0
End If
End Function
'生成BOM
'返回值:BOM所占字节
'fmt:[in]编码类型
'dwFirst:[out]文件最开始的4个字节
Public Function UEFMakeBOM(ByVal fmt As UnicodeEncodeFormat, ByRef dwFirst As Long) As Long
Select Case fmt
Case UEF_UTF8
dwFirst = HBFBBEF
UEFMakeBOM = 3
Case UEF_UTF16LE
dwFirst = HFEFF
UEFMakeBOM = 2
Case UEF_UTF16BE
dwFirst = HFFFE
UEFMakeBOM = 2
Case UEF_UTF32LE
dwFirst = HFEFF
UEFMakeBOM = 4
Case UEF_UTF32BE
dwFirst = HFFFE0000
UEFMakeBOM = 4
Case Else
dwFirst = 0
UEFMakeBOM = 0
End Select
End Function
'判断文本文件的编码类型
'返回值:编码类型。文件无法打开时,返回UEF_Auto
'FileName:文件名
Public Function UEFCheckTextFileFormat(ByVal FileName As String) As UnicodeEncodeFormat
Dim hFile As Long
Dim dwFirst As Long
Dim nNumRead As Long
'打开文件
hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, ByVal 0)
If INVALID_HANDLE_VALUE = hFile Then '文件无法打开
UEFCheckTextFileFormat = UEF_Auto
Exit Function
End If
'判断BOM
dwFirst = 0
Call ReadFile(hFile, dwFirst, 4, nNumRead, ByVal 0)
nNumRead = UEFCheckBOM(dwFirst, UEFCheckTextFileFormat)
'Debug.Print nNumRead
'关闭文件
Call CloseHandle(hFile)
End Function
'读取文本文件
'返回值:读取的文本。返回vbNullString表示文件无法打开
'FileName:[in]文件名
'fmt:[in,out]使用何种文本编码格式来读取文本。为UEF_Auto时表示自动判断,且在fmt参数返回文本所用编码格式
Public Function UEFLoadTextFile(ByVal FileName As String, Optional ByRef fmt As UnicodeEncodeFormat = UEF_Auto) As String
Dim hFile As Long
Dim nFileSize As Long
Dim nNumRead As Long
Dim dwFirst As Long
Dim CurFmt As UnicodeEncodeFormat
Dim cbBOM As Long
Dim cbTextData As Long
Dim CurCP As Long
Dim byBuf() As Byte
Dim cchStr As Long
Dim I As Long
Dim byTemp As Byte
'判断fmt范围
If fmt UEF_Auto Then
If fmt [_UEF_Min] Or fmt [_UEF_Max] Then
GoTo FunEnd
End If
End If
'打开文件
hFile = CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, ByVal 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, ByVal 0)
If INVALID_HANDLE_VALUE = hFile Then '文件无法打开
GoTo FunEnd
End If
'判断文件大小
nFileSize = GetFileSize(hFile, nNumRead)
If nNumRead 0 Then '超过4GB
GoTo FreeHandle
End If
If nFileSize 0 Then '超过2GB
GoTo FreeHandle
End If
'判断BOM
dwFirst = 0
Call ReadFile(hFile, dwFirst, 4, nNumRead, ByVal 0)
cbBOM = UEFCheckBOM(dwFirst, CurFmt)
'恢复文件指针
If fmt = UEF_Auto Then '自动判断
fmt = CurFmt
'cbBOM = cbBOM
Else '手动设置编码
If fmt = CurFmt Then '若编码相同,则忽略BOM标记
'cbBOM = cbBOM
Else '编码不同,那么都是数据
cbBOM = 0
End If
End If
Call SetFilePointer(hFile, cbBOM, ByVal 0, FILE_BEGIN)
cbTextData = nFileSize - cbBOM
'读取数据
UEFLoadTextFile = ""
Select Case fmt
Case UEF_ANSI, UEF_UTF8
'判断应使用的CodePage
CurCP = IIf(fmt = UEF_UTF8, CP_UTF8, UEFCodePage)
VB 如何用 jmail 接收邮件
抄个自己的回答:
建议你去看阿江翻译的JMAIL开发文档:
把这几个对象看一下:
POP3。MESSAGES,MESSAGE,ATTS,ATT
过程:
1。先用POP3对象连接邮件服务(当然你邮箱要开POP设置)并接受到MESSAGES
2。取到MESSAGES后,轮循到MESSAGE对象后。
3。对MESSAGE解析,得到邮件标题,内容,收发人,
4。如果有附件还要对ATTS对象轮循并解析(可以把附件存在本地或写链接)
MESSAGES是信件集
MESSAGE是单封信件
ATTS是附件集
ATT是单个附件
————————————————————————
发信分割线
————————————————————————
拿个别人的回答改了一下,俺VB几乎没用过,只会VB。NET
先注册DLL
然后VB代码如下:
Private Sub Command1_Click()
SendMail "标题", "正文"
End Sub
Sub SendMail(Optional ByVal sSubject As String, _
Optional ByVal sBody As String)
Dim jmail
Set jmail = CreateObject("jmail.Message")
jmail.Charset = "gb2312"
jmail.Silent = False
jmail.Priority = 1 '邮件状态,1-5 1为最高
jmail.MailServerUserName = "XXX" 'Email帐号
jmail.MailServerPassWord = "XXX" 'Email密码
jmail.FromName = "XXX" '发信人姓名
jmail.From = "XXX@XXX.XXXX" '发邮件地址地址
jmail.Subject = sSubject '主题
jmail.AddRecipient "XXX@XXX.XXXX" '收信人地址
jmail.body = sBody '信件正文
jmail.Send ("smtp.163.com") 'SMTP服务器,如smtp.sohu.com
Set jmail = Nothing
End Sub
全了。FromName 和FROM 建议都用邮件地址,不然有的邮箱不收的
VB如何接收邮件
Visual Basic 6中发送邮件的新方法
用VB6编写发送邮件的程序,有多种E-mail组件可供选择,如MAPIMessages、IIS4.0附带的CDONTS(NTS Collaboration Data Objects)以及许多第三方厂商开发的Email软件等。本文介绍用CDONTS开发VB下的邮件程序方法。
1. 确认已安装SMTP服务器
首先,必须确认在IIS服务器上已安装SMTP服务器,这是安装Option Pack时被缺省安装的选项。如果SMTP服务器已安装,在System32目录下会存在一个名为cdonts.dll的文件。
2. 最简单的邮件发送程序
以下是一个最简单的邮件发送程序,它由me@hotmail.net向abc@263.net发出一封标题为“Title”、内容为“Hello”的E-mail:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
ObjMail.Send "me@hotmail.net ", "abc@263.net","Title","Hello"
Set objMail=nothing
End Sub
3. 发送邮件附件
如果有附加的文件需要随同邮件传送,可以使用CDONTS的AttachFile方法:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
With ObjMail
.From= "me@hotmail.net "
.To= "abc@263.net"
.Subject="Title"
.Body="Hello"
.AttachFile "c:\document\ sample.doc","sample.doc"
.Send
End With
Set objMail=nothing
End Sub
4. CDONTS组件常用属性和方法
CDONTS组件常用的属性和方法列举如下:
属性:
Version:返回CDONTS组件的版本号
MailFormat:邮件格式,1-普通文本类型;0-MIME类型
Cc:设置一个或多个参阅的邮件地址
From:邮件发送者的地址
To :邮件接受者的地址
Subject:标题
Body:内容
BodyFormat:内容格式,1-普通文本;0-超文本
方法:
AttachFile:附加一个文件
AttachURL:附加一个地址
Send:发送邮件
5. 发送超文本格式的E-mail
你一定见到过许多使用超文本格式的E-mail,其中不但可以有图片、声音,甚至还可以嵌入动画。如果给你的朋友也发送一封这样的邮件,一定会带给他(她)意外的惊喜,因为这用一般的邮件发送程序是无能为力的。以下使用CDONTS组件发送一个HTML格式的邮件,其中包含有一幅名为sample.gif的图片,程序如下:
Private Sub cmdSendMail_Click()
Dim objMail as Object
Set objMail=CreateObject("CDFONTS.DLL")
Dim strHTML as String
StrHTML=""
StrHTML= StrHTML+""
StrHTML = StrHTML +"
用CDONTS发送Email的例子"
StrHTML= StrHTML+"
"
StrHTML= StrHTML+"
以上例子嵌入了图片sample.gif
"
StrHTML= StrHTML+""
With ObjMail
.From= "me@hotmail.net "
.To= "abc@263.net"
.Subject="Title"
.Body=strHTML
.AttachURL "c:\mydata\sample.gif","sample.gif"
.BodyFormat=0
.EmailFormat=0
.Send
End With
Set objMail=nothing
End Sub
到这里,相信大家一定发现SMTP邮件处理的一个缺陷了。SMTP服务器接收你的输出消息,但并不做发送者名字和地址的验证,这本是由SMTP的异步发送机制所决定的,但有人可能别有用心地用它来假扮别人发送邮件!本文强烈建议各位切勿轻易试用,一旦让ISP知道你的行径,你的帐号极可能会被立即删除。
新闻标题:vb.net读取邮件标题 vb发送邮件
链接URL:http://cdiso.cn/article/dodjchc.html