[VB.Net]發送G-Mail模組

以GMail發縮郵件之模組

  1. Imports System.Net

  2. Module GMail

  3.     ''' <summary>
  4.     ''' 透過SMTP協定發送G-Mail郵件。
  5.     ''' </summary>
  6.     ''' <param name="Account">用來發送郵件的帳號</param>
  7.     ''' <param name="Password">用來發送帳號的密碼</param>
  8.     ''' <param name="Sender">寄件者,Ex: Inndy<Inndy.mail@gmail.com></param>
  9.     ''' <param name="Recipients">寄件者,Ex: Inndy<Inndy.mail@gmail.com></param>
  10.     ''' <param name="Title">郵件標題</param>
  11.     ''' <param name="Body">郵件內容</param>
  12.     ''' <remarks></remarks>
  13.     Public Sub SendGMail(ByVal Account As String, ByVal Password As String, ByVal Sender As String, ByVal Recipients As String, ByVal Title As String, ByVal Body As String)
  14.         Dim MySmtp As New System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
  15.         MySmtp.Credentials = New System.Net.NetworkCredential(Account, Password)
  16.         MySmtp.EnableSsl = True
  17.         MySmtp.Send(Sender, Recipients, Title, Body)
  18.     End Sub
  19. End Module
複製代碼
存成模組使用,Gmail帳號請記得設定SMTP寄信。


使用範例:
  1. SendGMail("123.mail@gmail.com", "Password", "HAHAHA", "1234567635@kimo.com", "測試郵件標題", "郵件內容")

留言

本月最夯

偷用電腦,怎知?事件檢視器全記錄!(開機時間、啟動項時間...)