Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SMTPClient question Expand / Collapse
Author
Message
Posted Wednesday, November 14, 2012 8:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 20, 2013 11:19 AM
Points: 11, Visits: 72
I have a package using the Send Email Task.
On the SMTP connection, I have the smtp server specified and the Use Windows Authentication checked and the Enable Secure Sockets Layer unchecked.
Now, I want to send an email that has some data from a table embedded in the body.
So, I have added a Script Task with the following code:
Dim myHtmlMessage As MailMessage
Dim mySmtpClient As SmtpClient

myHtmlMessage = New MailMessage("FromEmailaddress", "ToEmailAddress", "Test", Msg)
mySmtpClient = New SmtpClient("smtp.server")
mySmtpClient.Credentials = CredentialCache.DefaultNetworkCredentials
myHtmlMessage.IsBodyHtml = True

Try
mySmtpClient.Send(myHtmlMessage)
Catch ex As Exception
MsgBox(ex.Message.ToString)
Dts.TaskResult = Dts.Results.Failure
End Try

The FromEmail and ToEmail are my own network email and the SMTPClient is my companies SMTP server, which is the same entry I had in the SMTP Connection Manager for the Send Email Task.
When I run the code, I don't get any errors but I never receive the email.
I'm trying to figure out why the Send Email Task works but this code does not.
Any help would be great.



Post #1384683
Posted Wednesday, November 14, 2012 8:57 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 6:53 AM
Points: 5,132, Visits: 4,922
What type of mail server do you use for SMTP? If its Exchange and you use the mail relay functionaity you need to ensure that you allow the IP address of the server where the mail is being sent from is allow to connect and send via the mail relay admin GUI, there are two places you need to add the IP.
Then also check that you dont have some sort of antivirus issue going on where it blocks mass mail worms, just to be on the safe side as I know from past experiences we had issues with McAfee stopping the mail services of SQL from sending and needed to be over-ridden by en ePO policy change.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1384695
Posted Wednesday, November 14, 2012 9:30 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, February 20, 2013 11:19 AM
Points: 11, Visits: 72
The server is Exchange. Anti-virus is not an issue.
As far as IP addresses go, wouldn't I have the same issue running the Send Email task (which works) on the same server??



Post #1384729
Posted Thursday, November 15, 2012 2:11 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 6:53 AM
Points: 5,132, Visits: 4,922
Doh, yeah I missed that part when reading your post, my bad, sorry on that.

Could you not make use of using DBMail instead if your passing over the results of a query via an execute SQL task instead of creating a script task to do it?




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1385013
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse