Welcome to Dream.In.Code
Become a VB Expert!

Join 149,967 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,369 people online right now. Registration is fast and FREE... Join Now!




VBscript sending 2 separate email in the same execute

 
Reply to this topicStart new topic

VBscript sending 2 separate email in the same execute

ismailc
9 Jan, 2008 - 02:21 AM
Post #1

New D.I.C Head
*

Joined: 14 Sep, 2007
Posts: 37



Thanked: 1 times
My Contributions
Hi, I need Help Please!

The code works to send one mail with one html message.
But now i want to send another mail on the same execute!
Send mail works fine:(First Email) but when i include the second email code it sends successfully but it has both HTML messages (HTMLBody) in
"test Message2" for only the second email.

CODE

'FIRST EMAIL
  SMTPServer = "srv08-za004"
  From = "Process@parmalat.co.za"
  GenericSendmail SMTPserver, From, Recipient, Subject, Message
  Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message)
  set msg = CreateObject("CDO.Message")
  msg.From = "ismailc@parmalat.co.za"
  msg.To = "ismailc@parmalat.co.za"
  msg.Subject = 'Subject"
  msg.HTMLBody = "test"
  msg.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
  msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  msg.Configuration.Fields.Update
  msg.Send
  End Sub

'Now I'm trying to send another one SECOND EMAIL
  SMTPServer2 = "srv08-za004"
  From2 = "Process@parmalat.co.za"
  GenericSendmail SMTPserver2, From2, Recipient2, Subject2, Message2
  Sub GenericSendmail (SMTPserver, From2, Recipient2, Subject2, Message2)
   set msg2 = CreateObject("CDO.Message")
   msg2.From = "ismailc@parmalat.co.za"
   msg2.To = "ismailc@parmalat.co.za"
   msg2.Subject = "Subject2"
   msg2.HTMLBody = "Message2"
   msg2.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer2
   msg2.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
   msg2.Configuration.Fields.Update
   msg2.Send
   End Sub



Please Assist!
Regards,
User is offlineProfile CardPM
+Quote Post

baavgai
RE: VBscript Sending 2 Separate Email In The Same Execute
9 Jan, 2008 - 03:46 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,282



Thanked: 136 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
You have a perfectly good GenericSendmail procedure, use it! Unfortunately, I don't think it's doing what you think it's doing. From your code, this is what you're doing. Start from there.

CODE

'FIRST EMAIL
GenericSendmail "srv08-za004", "ismailc@parmalat.co.za", "ismailc@parmalat.co.za", "", "test"

'SECOND EMAIL
GenericSendmail "srv08-za004", "ismailc@parmalat.co.za", "ismailc@parmalat.co.za", "Subject2", "Message2"

Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message)
    Dim msg
    set msg = CreateObject("CDO.Message")
    msg.From = From
    msg.To = Recipient
    msg.Subject = Subject
    msg.HTMLBody = Message
    msg.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
    msg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    msg.Configuration.Fields.Update
    msg.Send
    ' added, release object, may help
    set msg=nothing
End Sub


Hope this helps.

User is online!Profile CardPM
+Quote Post

ismailc
RE: VBscript Sending 2 Separate Email In The Same Execute
9 Jan, 2008 - 05:44 AM
Post #3

New D.I.C Head
*

Joined: 14 Sep, 2007
Posts: 37



Thanked: 1 times
My Contributions
Hi, Thanks for the Help & your kindness - really gratefull
As you noticed I'm a beginner. I'm using Flowcentric which uses vbscript.
The reason why i defined it twice is that it's based on certain if conditions: Yes to execute both & no only to execute the one.
The email gets sent to different uses with different messages.

Got it going:

SMTPServer = "srv08-za004"
From = "Process@parmalat.co.za"
GenericSendmail2 SMTPserver, From, Recipient, Subject, Message
Sub GenericSendmail2 (SMTPserver, From, Recipient, Subject, Message)
set msg2 = CreateObject("CDO.Message")
msg2.From = From
msg2.To = Recipient2
msg2.Subject = Subject2
msg2.HTMLBody = message2
msg2.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
msg2.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msg2.Configuration.Fields.Update
msg2.Send
End Sub

User is offlineProfile CardPM
+Quote Post

baavgai
RE: VBscript Sending 2 Separate Email In The Same Execute
9 Jan, 2008 - 06:33 AM
Post #4

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,282



Thanked: 136 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Glad it's working for you. However, be aware that it may not be doing what you think.

Here's a quick breakdown of your last posted code.

CODE
SMTPServer = "srv08-za004"
From = "Process@parmalat.co.za"
GenericSendmail2 SMTPserver, From, Nothing, Nothing, Nothing
Sub GenericSendmail2 (SMTPserver, From, Recipient, Subject, Message)
set msg2 = CreateObject("CDO.Message")
msg2.From = From
msg2.To = Nothing ' Recipient2, Never Defined
msg2.Subject = Nothing ' Subject2, Never Defined
msg2.HTMLBody = Nothing ' message2, Never Defined
msg2.Configuration.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
msg2.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msg2.Configuration.Fields.Update
msg2.Send
End Sub


User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 06:24PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month