@dvmu 在吗? 他那个发送邮件的玩意我还太明白
vb.net吧
全部回复
仅看楼主
level 7
暴牙归来 楼主
Imports System.net.Mail
Imports System.Text
Imports System.Security
Imports System.Net.Sockets
Public Class 邮件发送
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chk.CheckedChanged
If chk.Checked = True Then
txtName.Enabled = True
txtPassword.Enabled = True
Else
txtName.Enabled = False
txtPassword.Enabled = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim mail As New MailMessage()
mail.From = New MailAddress(txtFrom.Text)
mail.To.Add(txtTo.Text)
'set the content
mail.Subject = txtSubject.Text
mail.Body = txtContent.Text
''specify the priority of the mail message
mail.Priority = MailPriority.High
'to add custom headers, we use the Headers.Add(...) method to add headers to the
'.Headers collection
mail.Headers.Add("X-Company", "JOHN NG SDN BHD")
mail.Headers.Add("X-Location", "Malaysia")
Dim smtp As New SmtpClient(txtSMTP.Text)
If chk.Checked = True Then
smtp.Credentials = New System.Net.NetworkCredential(txtName.Text, txtPassword.Text)
End If
'检测是否有附件
If TextBox1.Text.Trim <> "" Then ''带附件
If Dir(TextBox1.Text.Trim) <> "" Then
Dim attach As Net.Mail.Attachment = New Net.Mail.Attachment(TextBox1.Text)
mail.Attachments.Add(attach)
End If
End If
Try
smtp.Send(mail)
MsgBox("恭喜,邮件已经发送到指定的邮件地址.", MsgBoxStyle.Information, "邮件发送示例")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "邮件发送失败")
End Try
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.OpenFileDialog1.Title = "选择附件"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
TextBox1.Text = OpenFileDialog1.FileName
End If
End Sub
End Class
2016年06月19日 10点06分 1
level 7
暴牙归来 楼主
这件事还得从一条帖子“珍藏源码大放送”(https://tieba.baidu.com/p/4462155280)说起
@dvmu
@
Nukepayload2
2016年06月19日 10点06分 2
level 7
暴牙归来 楼主
今天下午我编写软件时缺少灵感,于是我浏览了那条帖子,发现里面的收发邮件程序写的不错,于是添加他为自己软件的组件。但发送失败了········
2016年06月19日 10点06分 3
level 12
这吧是你的了 骚年[滑稽]
2016年06月19日 10点06分 4
你让@夜闻香 情何以堪[揉脸]
2016年06月19日 11点06分
1