通过 vb.net 将邮件另存为文本文件时遇到问题。我完成了以下任务: -
public sub rearmail()
Dim pop3Client As Pop3Client
If (Session("Pop3Client") Is Nothing) Then
pop3Client = New Pop3Client
pop3Client.Connect("pop.gmail.com", 995, True)
pop3Client.Authenticate("mymail@gmail.com", "password")
Session("Pop3Client") = pop3Client
Else
pop3Client = CType(Session("Pop3Client"), Pop3Client)
End If 'connect to the inbox with username and pass word authentication
Dim message As Message = pop3Client.GetMessage(0)
dim frm as string ' to store from address
dim subj as string ' to store the subject
dim mdate as date ' to store the date and time
frm=message.Headers.From.Address
subj= message.Headers.Subject
mdate=message.Headers.DateSent
'**** no i need to read the mail message and save it as a notepad file ****
end sub
我曾尝试使用以下方式阅读邮件: -
Dim message As Message = pop3Client.GetMessage(0)
如下: -
Dim str As MailMessageEventArgs
dim strmsg as string
strmsg=str..Message.Body.ToString 'error null error exception at run time
strmsg=message.MessagePart.Body ' nothing will return
我很喜欢消息对象,但是我没有达到目标,我希望这个社区的专家可以帮助我克服这个问题,
提前谢谢.....♥
答案 0 :(得分:0)
感谢那个尝试解决问题的人,我现在得到了解决方案,我希望与您分享。这是读取邮件正文内容的代码段; -
Dim messagePart As MessagePart = message.MessagePart.MessageParts(0)
MsgBox(messagePart.BodyEncoding.GetString(messagePart.Body))