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!
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
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.
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
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
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