How to write line for CC in SMTP code?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 276 Views - Last Post: 18 January 2018 - 03:41 PM Rate Topic: -----

#1 SteveHi  Icon User is offline

  • New D.I.C Head

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

How to write line for CC in SMTP code?

Posted 18 January 2018 - 12:28 PM

What is the correct way, please, to script a line for CC in SMTP code?

Neither of these work:

myMessage.CC.Add(New MailAddress("[email protected]")) 'Webmaster's assistant

myMessage.CC.Add("[email protected]") 'Webmaster's assistant



What happens is that the Webmaster receives (from an online form) his email and his assistant's email address ([email protected]) is visible in the message sent to the Webmaster, but info2 himself does not get his copy to how own inbox.

Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: How to write line for CC in SMTP code?

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13747
  • View blog
  • Posts: 54,901
  • Joined: 12-June 08

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 12:32 PM

Wouldn't you use System.Net.Mail.mailmessage and not just, solely, the SMTPclient?
Was This Post Helpful? 0
  • +
  • -

#3 SteveHi  Icon User is offline

  • New D.I.C Head

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

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 01:17 PM

Thanks for your reply.

At the top of the SMTP code, I have:

Imports System
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Net
[b]Imports System.Net.Mail[/b]
Imports System.Net.Mime
Imports System.IO


Is that what you mean?

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13747
  • View blog
  • Posts: 54,901
  • Joined: 12-June 08

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 01:23 PM

No.. like actually declare an instance of mailmessage .. set the to, body, from, cc, subject, etc there and use the smtp's "send" with the mailmessage instance.
Was This Post Helpful? 0
  • +
  • -

#5 SteveHi  Icon User is offline

  • New D.I.C Head

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

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 01:30 PM

Yes, I have this. It works apart from the CC:

Protected Sub SendEmail_Click(sender As Object, e As System.EventArgs) Handles SendEmail.Click

        Dim myMessage As New MailMessage
        Dim Smtpserver As New SmtpClient

            Dim user_name As String = Request.Form("user_name")
            Dim user_email As String = Request.Form("user_email")
            Dim user_subject As String = Request.Form("user_subject")
            Dim user_message As String = Request.Form("user_message")

            myMessage.From = New MailAddress(user_email) 'User's email
            myMessage.To.Add(New MailAddress("[email protected]")) 'Webmaster
            'myMessage.CC.Add(New MailAddress("[email protected]")) 'Webmaster's assistant

            myMessage.CC.Add("[email protected]")


            myMessage.Subject = user_subject
            myMessage.Body = user_message
            myMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
            myMessage.IsBodyHtml = True
            myMessage.Priority = MailPriority.High

            Smtpserver.DeliveryMethod = SmtpDeliveryMethod.Network
            Smtpserver.Host = ("IP_add")
            Smtpserver.Port = 25
            Smtpserver.EnableSsl = False

            Dim basicAuthenticationInfo As New System.Net.NetworkCredential("[email protected]", "pwd")
            Smtpserver.Credentials = basicAuthenticationInfo
            'Smtpserver.UseDefaultCredentials = False
            Smtpserver.Send(myMessage)

            myMessage.Dispose()
            myMessage = Nothing
            Smtpserver = Nothing

                  End Sub

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13747
  • View blog
  • Posts: 54,901
  • Joined: 12-June 08

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 01:33 PM

the mailmessage.cc has an add that takes a string. Throw in the email address.
Was This Post Helpful? 0
  • +
  • -

#7 SteveHi  Icon User is offline

  • New D.I.C Head

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

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 01:43 PM

Haven't I done that here?

 myMessage.CC.Add(New MailAddress("[email protected]")) 'Webmaster's assistant

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13747
  • View blog
  • Posts: 54,901
  • Joined: 12-June 08

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 01:48 PM

This:
myMessage.CC.Add("[email protected]")
Was This Post Helpful? 0
  • +
  • -

#9 SteveHi  Icon User is offline

  • New D.I.C Head

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

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 01:51 PM

I have that in the code above (one is commented out):

myMessage.CC.Add("[email protected]")


It doesn't work
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13747
  • View blog
  • Posts: 54,901
  • Joined: 12-June 08

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 01:53 PM

Then something is wonky going on beyond the code. What happens when both emails are in the 'to'? Did you check spam folders? Junk folders? Outlook-esque rules?
Was This Post Helpful? 0
  • +
  • -

#11 SteveHi  Icon User is offline

  • New D.I.C Head

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

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 02:24 PM

How would I write both mails under TO?
Was This Post Helpful? 0
  • +
  • -

#12 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13747
  • View blog
  • Posts: 54,901
  • Joined: 12-June 08

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 02:29 PM

How do you add to a collection?

myMessage.To.add("asdfsadfsadf")
Was This Post Helpful? 0
  • +
  • -

#13 SteveHi  Icon User is offline

  • New D.I.C Head

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

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 02:33 PM

I already have this:

 myMessage.To.Add(New MailAddress("[email protected]")) 'Webmaster


Like this?

 myMessage.To.Add(New MailAddress("[email protected]", "[email protected]")) 'Webmaster

Was This Post Helpful? 0
  • +
  • -

#14 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13747
  • View blog
  • Posts: 54,901
  • Joined: 12-June 08

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 02:55 PM

Dude.. no.

It's a collection. Just do one .add with your string for email1.. then the line below do .add for the string that is email2.
Was This Post Helpful? 0
  • +
  • -

#15 SteveHi  Icon User is offline

  • New D.I.C Head

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

Re: How to write line for CC in SMTP code?

Posted 18 January 2018 - 03:26 PM

I will compile and upload and post back - thanks
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2