添加附件,Cc& Bcc在Visual Basic 2010中

时间:2015-02-13 17:19:25

标签: vb.net

我是新手,我不知道如何添加附件,Cc&密件抄送在一个vb项目中。我添加了一个标有'发送'的按钮(Button1),其代码如下:

        Dim message As System.Net.Mail.MailMessage
        Dim smtp As New System.Net.Mail.SmtpClient(smtptxtbx.Text, Port.Value)

        Try
            message = New System.Net.Mail.MailMessage(Emailtxtbx.Text, totxtbx.Text, subtxtbx.Text, RichTextBox1.Text)

            If ssl.Checked = True Then
                smtp.EnableSsl = True
            Else
                smtp.EnableSsl = False
            End If


            If authentication.Checked = True Then
                smtp.Credentials = New System.Net.NetworkCredential(usernametxtbx.Text, passwordtxtbx.Text)
            Else
                smtp.Credentials = Nothing
            End If

            If attachment.Checked = True Then
                'I want to add the attachment code here
            End If
            If Cc.Checked = True Then
                'I want to add the Cc code here
            End If
            If Bcc.Checked = True Then
                'I want to add the Bcc code here
            End If


            Try

                smtp.Send(message)
                MessageBox.Show("Message Sent Successfully", " OneClick Email Sender", MessageBoxButtons.OK, MessageBoxIcon.Information)
                ProgressBar1.Value = 100
            Catch exc As Net.Mail.SmtpException
                MessageBox.Show("Please check your internet connection. And make sure that you fill everything correct.", " OneClick Email Sender", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
       Catch ex As Exception
            MsgBox("Please fill the details for sending the Email.")
       End Try

我该怎么做?

1 个答案:

答案 0 :(得分:0)

得到答案...... :-p 附件代码:

message.Attachments.Add(New Attachment(attachmenttxtbx.Text))

cc和bcc的代码:

message.CC.Add(cctxtbx.Text)
message.Bcc.Add(bcctxtbx.Text)

感谢helrich和sparkyword !!!