Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
May i know how to use bcc in the add method? I am using stmp gmail in vb.net visual studios 2010.
& how do I add multiple recipients ?

On top of that, does anyone knows how to retrieve the email from database into this line?
VB
Dim bcc As New MailAddress("fionatan06@gmail.com")
           mail.Bcc.Add(bcc)

Urgent! Thank you.
my code is :

VB
Protected Sub SendMail_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles SendMail.Click

        Try
            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New  _
Net.NetworkCredential("fionatan06@gmail.com", "bananaboat")
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            SmtpServer.EnableSsl = True
            mail = New MailMessage()
            mail.From = New MailAddress("fionatan06@gmail.com")
            mail.To.Add("fionatyl@hotmail.com")
            Dim bcc As New MailAddress("fionatan06@gmail.com")
            mail.Bcc.Add(bcc)
            mail.Subject = TextBox1.Text
            mail.IsBodyHtml = True
            mail.Body = TextBox2.Text + "<br></br><br></br>This is an auto-generated message. Please do not reply. Thank you.<br></br><br></br>Colore"
            Dim MyAttachment As Attachment = New Attachment("C:\Users\Admin\Desktop\EAIPJ(Coloré-Rachel,Peiwen,Sherry,Fiona)\Coloré\Images\BLACK SHATTER.jpg")
            mail.Attachments.Add(MyAttachment)
            SmtpServer.Send(mail)
            MsgBox("Mail Send")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
Posted
Updated 27-Jun-12 7:05am
v5

1 solution

Here is an example of how to send email through Gmail using VB.NET:

http://www.emailarchitect.net/easendmail/kb/vbnet.aspx?cat=2[^]

To include an email in the BCC field, you need to add it to the BCC collection. See here for a further explanation:

http://msdn.microsoft.com/en-us/library/system.net.mail.mailmessage.bcc.aspx[^]

The code would look like this:
VB
MailAddress bcc = new MailAddress("example@dummy.int");
oMail.Bcc.Add(bcc);


To add multiple email addresses to this list, you just keep adding them, like so:
C#
MailAddress bcc = new MailAddress("example@dummy.int");
oMail.Bcc.Add(bcc);
bcc = new MailAddress("example2@dummy.int");
oMail.Bcc.Add(bcc);
 
Share this answer
 
v3
Comments
Fiona Tan 27-Jun-12 11:24am    
how come i tried but the error is " property Bcc is read only "
Tim Corey 27-Jun-12 11:35am    
I apologize. I wrote that code quickly and I forgot that BCC is a collection and not a single value. I've updated my answer with working code. I've also included a link to MSDN where it explains BCC.
Fiona Tan 27-Jun-12 11:44am    
thank you. amay i know if I want to send it to many recipients in bcc, how do i do that?
Tim Corey 27-Jun-12 11:50am    
I've updated my solution to show you. Basically, since BCC is a collection, you can just keep adding addresses. In my example, I just reinitialize the bcc variable with a new address and then add that to the oMail.Bcc collection.
Fiona Tan 27-Jun-12 11:45am    
may

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900