' 兩個收件人:GetMail1@gmail.com和GetMail2@gmail.com
Dim To_Address As String = "a.tw@gmail.com;b@yahoo.com.tw"
' 設定SMTPserver
Dim SMTP_Server As New System.Net.Mail.SmtpClient("smtp.sig.com")
Dim Mailmsg As New System.Net.Mail.MailMessage Dim MailBodyHtml As String
' 設定一個信件的附檔
Dim mail_attachment As New System.Net.Mail.Attachment("C:\test1.txt")
Mailmsg.IsBodyHtml = True ' 為html內容格式
' 此信的寄件人 Mailmsg.From = New Net.Mail.MailAddress(b@sig.com., "寄件人")
Mailmsg.Subject = "peterlion_主旨"
MailBodyHtml = "peterlion_Mail Message First"
MailBodyHtml &= "Mail Message Second"
Mailmsg.Body = MailBodyHtml
' 把附檔加入到Mail Mailmsg.Attachments.Add(mail_attachment)
' 將字串裡的;分為多個收件人
For Each MA As String In To_Address.Split(";")
Mailmsg.To.Add(New Net.Mail.MailAddress(MA, "收件人"))
Next
' 密件副本收件人 'Mailmsg.Bcc.Add(New Net.Mail.MailAddress("GetMail3@gmail.com", "密件副本")) Mailmsg.Priority = Net.Mail.MailPriority.High
' Smtp(Server) 的帳號與密碼 SMTP_Server.Credentials = New System.Net.NetworkCredential("username", "pwd")
'如果 SMTP 主機需要認證,必須先設定認證後才能呼叫這個方法。若要指定認證,請使用 UseDefaultCredentials 或 Credentials 屬性。
SMTP_Server.Send(Mailmsg)
MsgBox("OK")
沒有留言:
張貼留言