6 Replies - 359 Views - Last Post: 04 April 2018 - 09:52 AM

#1 SteveHi   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 07-June 15

Correct coding for CC and BCC in SMTP?

Posted 04 April 2018 - 06:36 AM

Hello

In my SMTP code for CC and BCC, I have the following:

  

Dim CC As MailAddress = New MailAddress("[email protected]")
myMessage.CC.Add(New MailAddress("[email protected]"))

Dim BCC As MailAddress = New MailAddress(user_email)
myMessage.CC.Add(New MailAddress(user_email)) 


Is it really necessary to repeat - in the second line of each pair - the email addresses, or is there a simpler way, please.

Thank you

Is This A Good Question/Topic? 0
  • +

Replies To: Correct coding for CC and BCC in SMTP?

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14865
  • View blog
  • Posts: 59,306
  • Joined: 12-June 08

Re: Correct coding for CC and BCC in SMTP?

Posted 04 April 2018 - 06:44 AM

Why wouldn't you just use lines 2 and 5 since you are not using the variables CC or BCC.
Was This Post Helpful? 0
  • +
  • -

#3 SteveHi   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 07-June 15

Re: Correct coding for CC and BCC in SMTP?

Posted 04 April 2018 - 08:59 AM

I thought it was necessary to declare everything - CC, BCC, subject, etc?

So this should suffice:

 myMessage.CC.Add(New MailAddress("[email protected]"))
 myMessage.BCC.Add(New MailAddress(user_email))




Thanks again.

This post has been edited by SteveHi: 04 April 2018 - 09:00 AM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14865
  • View blog
  • Posts: 59,306
  • Joined: 12-June 08

Re: Correct coding for CC and BCC in SMTP?

Posted 04 April 2018 - 09:07 AM

It's about knowing what is happening where.

This line.. the 'cc.add' needs a 'mailaddress' variable, right? Using 'new' creates an instances of the 'mailaddress' variable and feeds it into 'cc.add'.
5  myMessage.CC.Add(New MailAddress(user_email))


This creates a variable instance of 'mailaddress' called 'bcc'. .. then it's done.
4  Dim BCC As MailAddress = New MailAddress(user_email)


You could have easily done something like this where the variable is used.

myMessage.CC.Add(BCC)

Was This Post Helpful? 0
  • +
  • -

#5 SteveHi   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 07-June 15

Re: Correct coding for CC and BCC in SMTP?

Posted 04 April 2018 - 09:29 AM

For this to work:

myMessage.CC.Add(BCC)


Wouldn't I need this beforehand?

Dim CC As MailAddress = New MailAddress("[email protected]")
Dim BCC As MailAddress = New MailAddress(user_email)



Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14865
  • View blog
  • Posts: 59,306
  • Joined: 12-June 08

Re: Correct coding for CC and BCC in SMTP?

Posted 04 April 2018 - 09:30 AM

Well.. yeah, sorry if that wasn't clear. If you want to use the variable BCC you would need to declare it before you use it in the .add.
Was This Post Helpful? 0
  • +
  • -

#7 SteveHi   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 07-June 15

Re: Correct coding for CC and BCC in SMTP?

Posted 04 April 2018 - 09:52 AM

You have cleared things up - thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1