I need to create a vb script in order to Send an Email with Attachments. I am having no luck creating a simple script to email me in test with no attachments.
In My Package i Have Variables Assigned for the following:
In My Script Task I have ReadOnlyVariables for MailTo, MailFrom, SmtpServer ReadWriteVariable = MailSubject (I will try the message after I get it to just email successfully
Here is my script
Can Someone please help? This shows green as successful but no error messages ever appear and no messages appear.
Do you have to do this with VB? Can you not use Database Mail? What version of SQL Server are you running?
answered Feb 09 '11 at 09:40 AM
The code has some small problems. Here is what you can try to make it work:
Add this line to the code to make sure that the message is sent in Html format
Optionally set the priority:
If you need to add any attachments to it then use this:
And finally, please consider wrapping your message into the using block to prevent memory leaks. MailMessage type implements IDisposable interface, and so any instance of it should be disposed promptly after use.
There was a good example of this on MSSQLTips.com - [http://www.mssqltips.com/tip.asp?tip=1753]
You might try scarfing their example code to get you up and running quickly. You get a using statement for free by using their code (this addresses the memory leak issue raised by Oleg).: h ttp://www.mssqltips.com/tip.asp?tip=1753