{"id":88,"date":"2012-02-23T07:16:52","date_gmt":"2012-02-23T13:16:52","guid":{"rendered":"https:\/\/www.asberry.org\/blog_tech\/?p=88"},"modified":"2012-02-23T07:45:05","modified_gmt":"2012-02-23T13:45:05","slug":"sending-an-email-with-visual-basic","status":"publish","type":"post","link":"https:\/\/asberry.org\/blog_tech\/?p=88","title":{"rendered":"Sending an email with Visual Basic"},"content":{"rendered":"<pre class=\"brush: vb; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\nImports System\r\nImports System.Net\r\nImports System.Data\r\nImports System.Net.Mail\r\nImports System.IO\r\nImports System.Net.NetworkCredential\r\nImports Microsoft.SqlServer.Dts.Runtime\r\n\r\n&lt;System.AddIn.AddIn(&quot;ScriptMain&quot;, Version:=&quot;1.0&quot;, Publisher:=&quot;&quot;, Description:=&quot;&quot;)&gt; _\r\n&lt;System.CLSCompliantAttribute(False)&gt; _\r\nPartial Public Class ScriptMain\r\n Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase\r\n\r\nEnum ScriptResults\r\n Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success\r\n Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure\r\n End Enum\r\n\r\nPublic Sub Main()\r\n Dim oReader As StreamReader\r\n Dim sTo As String\r\n Dim sFrom As String = &quot;EnterpriseAccountTeam@pdstech.com&quot;\r\n Dim sCC As String\r\n Dim sMessage As String\r\n Dim sSubject As String\r\n Dim sJob_State As String\r\n Dim sJob_Status As String\r\n Dim sBranch As String\r\n Dim sRec() As String\r\n Dim sLine As String\r\n Dim linefeed As String = Constants.vbCrLf\r\n Try\r\n 'open file\r\n oReader = New StreamReader(&quot;C:\\Taleo\\TCC\\Prod\\Export\\Requisition\\EmailFile.csv&quot;)\r\n While oReader.Peek &lt;&gt; -1\r\n sLine = oReader.ReadLine()\r\n sRec = sLine.Split(Convert.ToChar(&quot;|&quot;))\r\n sTo = sRec(0)\r\n sCC = sRec(1)\r\n sSubject = &quot;A new requisition has been assigned to you. Req No: &quot; + sRec(2) + &quot; Job title: &quot; + sRec(3)\r\n sMessage = &quot;City: &quot; + sRec(4) + linefeed + &quot;State: &quot; + sRec(5) + linefeed\r\n sMessage += &quot;Client: &quot; + sRec(6) + linefeed + &quot;Job state: &quot; + sRec(7) + linefeed\r\n sMessage += &quot;Job status: &quot; + sRec(8) + linefeed + &quot;Branch: &quot; + sRec(9)\r\n 'Send Mail\r\n MailSend(sTo, sCC, sFrom, sSubject, sMessage)\r\n End While\r\n oReader.Close()\r\n\r\n\r\nCatch ex As Exception\r\n Dts.TaskResult = ScriptResults.Failure\r\n End Try\r\n Dts.TaskResult = ScriptResults.Success\r\n End Sub\r\n Public Sub MailSend(ByVal ToMail As String, ByVal ToCC As String, ByVal From As String, ByVal Subject As String, ByVal Message As String)\r\n\r\nDim smtpclient As New SmtpClient\r\n Dim mailmessage As New MailMessage\r\n Dim fromadd As New MailAddress(From)\r\n\r\nsmtpclient.Host = &quot;10.1.0.10&quot;\r\n smtpclient.Port = 25\r\n smtpclient.Credentials = CredentialCache.DefaultNetworkCredentials\r\n mailmessage.From = fromadd\r\n mailmessage.To.Add(ToMail)\r\n mailmessage.CC.Add(ToCC)\r\n mailmessage.Subject = CStr(Subject)\r\n mailmessage.Body = CStr(Message)\r\n\r\nsmtpclient.Send(mailmessage)\r\n\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Imports System Imports System.Net Imports System.Data Imports System.Net.Mail Imports System.IO Imports System.Net.NetworkCredential Imports Microsoft.SqlServer.Dts.Runtime &lt;System.AddIn.AddIn(&quot;ScriptMain&quot;, Version:=&quot;1.0&quot;, Publisher:=&quot;&quot;, Description:=&quot;&quot;)&gt; _ &lt;System.CLSCompliantAttribute(False)&gt; _ Partial Public Class ScriptMain Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase Enum ScriptResults Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure End Enum Public Sub Main() Dim oReader As StreamReader Dim sTo As String Dim sFrom As String = &quot;EnterpriseAccountTeam@pdstech.com&quot; Dim [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[9],"tags":[],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-visual-basic","author-aron"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4bBkH-1q","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/88","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=88"}],"version-history":[{"count":4,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":93,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=\/wp\/v2\/posts\/88\/revisions\/93"}],"wp:attachment":[{"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/asberry.org\/blog_tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}