|
查看: 1697|回复: 6
|
VB.NET 2008 Send Email
[复制链接]
|
|
|
各位高手,小弟想请教如何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
|
|
|
|
|
|
|
|
|
|
|
发表于 4-7-2011 07:22 PM
|
显示全部楼层
read text file
- Dim sr As StreamReader = New StreamReader(textfilepath, System.Text.Encoding.Unicode)
- Do While sr.Peek() >= 0
- Dim line As String = sr.ReadLine.Trim
- If line.Length > 0 Then
-
- End If
- Loop
- 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:
捫慭䁮畨敭散扭慯摲挮浯洮ⱹ档畵彩䀸潨浴楡⹬潣
步骤错了吗?还是写少了什么?因为我刚开始学习
谢谢高手回复!
太简单了@@ |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 21-8-2011 10:36 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|