佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1697|回复: 6

VB.NET 2008 Send Email

[复制链接]
发表于 4-7-2011 06:19 PM | 显示全部楼层 |阅读模式

各位高手,小弟想请教如何read email address from text file 之后 send email? 谢谢高人指点!
以下的code是可以执行 send email.
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Imports
System.Net.Mail
Imports
System.Net.Mail.SmtpClient
Imports
System.Net.Mail.MailMessage

Public
Class Form1
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim Mail As New MailMessage
Try
Mail.Subject =
"Test Email"
Mail.To.Add(
"you@yahoo.com,you2@hotmail.com")
Mail.From =
New MailAddress("you2@hotmail.com")
Mail.Body =
"This is an ownage email using VB.NET"
Dim SMTP As New SmtpClient("smtp.live.com")
SMTP.EnableSsl =
True
SMTP.Credentials =
New System.Net.NetworkCredential("you2@hotmail.com", "password")
SMTP.Port =
"587"
SMTP.Send(Mail)
MessageBox.Show(
"Sent!")
Catch ex As Exception
MessageBox.Show(
"Cannot send email: " & ex.Message)
End Try
End Sub

End
Class
回复

使用道具 举报


ADVERTISEMENT

发表于 4-7-2011 07:22 PM | 显示全部楼层
read text file

  1. Dim sr As StreamReader = New StreamReader(textfilepath, System.Text.Encoding.Unicode)

  2.         Do While sr.Peek() >= 0
  3.             Dim line As String = sr.ReadLine.Trim
  4.             If line.Length > 0 Then
  5.             
  6.             End If
  7.         Loop
  8.         sr.Close()
复制代码
回复

使用道具 举报

 楼主| 发表于 5-7-2011 09:38 AM | 显示全部楼层
回复 2# hanching
我把代码改成如一下:

Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
Dim textfilepath = "C:\csv\email_address.txt"
Dim sr As StreamReader = New StreamReader(textfilepath, System.Text.Encoding.Unicode)
Do While sr.Peek() >= 0
Dim TextLine As String = sr.ReadLine.Trim
If TextLine.Length > 0 Then
End If
txtRead.Text = TextLine
Loop
sr.Close()
End Sub

OUTPUT  of
txtRead.Text:
捫慭䁮畨敭散扭慯摲挮浯洮ⱹ档畵彩䀸潨浴楡⹬潣


步骤错了吗?还是写少了什么?因为我刚开始学习
谢谢高手回复!
回复

使用道具 举报

 楼主| 发表于 5-7-2011 09:57 AM | 显示全部楼层
File save as encoding ANSI 改 Unicode 就行了。
TQ VERY MUCH!!
回复

使用道具 举报

发表于 9-8-2011 07:34 AM | 显示全部楼层
顶你一下吧



















夜晨影院 影视界 正味网
回复

使用道具 举报

发表于 18-8-2011 07:02 PM | 显示全部楼层
Private Sub btnRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRead.Click
Dim textfilepath = "C:\csv\email_address.txt"
Dim sr As StreamReader = New StreamReader(textfilepath, System.Text.Encoding.Unicode)
Do While sr.Peek() >= 0
Dim TextLine As String = sr.ReadLine.Trim
If TextLine.Length > 0 Then
End If
txtRead.Text = TextLine
Loop
sr.Close()
End Sub

OUTPUT  of
txtRead.Text:
捫慭䁮畨敭散扭慯摲挮浯洮ⱹ档畵彩䀸潨浴楡⹬潣


步骤错了吗?还是写少了什么?因为我刚开始学习
谢谢高手回复!


太简单了@@
回复

使用道具 举报

Follow Us
 楼主| 发表于 21-8-2011 10:36 PM | 显示全部楼层
刚接触简单任务
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT


本周最热论坛帖子本周最热论坛帖子

ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 12-11-2025 05:21 AM , Processed in 0.091308 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表