使用System.Net.Mail

方法一(全寫在後置程式碼中)

 

 Imports System.Net.Mail

 

        Dim myMail As New MailMessage()

        '發送者
        myMail.From = New MailAddress("Arvin@gmail.com", "Arvin")

        '收件者
        myMail.To.Add(123@gmail.com)

        '隱藏收件者
        'myMail.Bcc.Add(456@gmail.com)

        '副本
        'myMail.CC.Add(789@gmail.com)

        '主題編碼格式
        'myMail.SubjectEncoding = Encoding.UTF8

        '主題
        myMail.Subject = "測試郵件"

        'HTML語法(true:開啟 false:關閉)
        myMail.IsBodyHtml = True

        '內文編碼格式
        'myMail.BodyEncoding = Encoding.UTF8

        '內文
        myMail.Body = "TEST<br>123"

        '附件
        ' myMail.Attachments.Add(New MailAttachment("c:\123.rar"))

        '建立SMTP連線
        Dim mySmtp As New SmtpClient

        '連線驗證
        mySmtp.Credentials = New System.Net.NetworkCredential("Arvin@gmail.com", "123456")

        '連接Port
        mySmtp.Port = 587

        'SMTP主機名
        mySmtp.Host = "smtp.gmail.com"

        '開啟SSL驗證
        mySmtp.EnableSsl = True

        '發送
        mySmtp.Send(myMail)

 


方法二(加入Web.config中)

Web.config>

<system.net>

       <mailSettings>

              <smtp>

                     <network host ="smtp.gmail.com" userName ="帳號@gmail.com"  port ="587" password ="密碼" />

              </smtp>

       </mailSettings>

</system.net>

 

page.aspx>

Dim mySmtp As new SmtpClient

Dim myMail As MailMessage = New MailMessage("發信者@gamil.com", "收信者@gmail.com", "標題", "內文")

mySmtp.Send(myMail)

 

創作者介紹

蛤什麼蛤?

joysdw12 發表在 痞客邦 PIXNET 留言(0) 人氣()