Posts

Showing posts with the label Auto Email Send

How to send Email using command in Windows

Image
You can not use Command Prompt directly to send an email, but using PowerShell allows you to use the underlying .Net Framework, you can easily create and send an  e-mail from the command line.  #this works, just sends a simple email $smtpServer = "your.webmailserver.com" $smtpFrom = "fromadress@webmailserver.com" $smtpTo = "todaddress@webmailserver.com" $smtpCc = 'ccdaddress@webmailserver.com' $smtpSubject = "This is a test email" $username = "username" $password = "password" $body = "your mail body goes here" $smtp = New-Object -TypeName "Net.Mail.SmtpClient" -ArgumentList $smtpServer $smtp.Credentials = New-Object system.net.networkcredential($username, $Password); $smtpBody = $body $SMTPMessage = New-Object System.Net.Mail.MailMessage($smtpFrom, $smtpTo, $smtpSubject, $smtpBody) $SMTPMessage.cc.Add($smtpCc) $SMTPMessage.IsBodyHTML=$true $smtp.Send($SMTPMessage) You can run this sc...

How to send email from a table in SQL Server

Image
Create a new table named  System Generated Email in SQL Server Database: CREATE TABLE [dbo].[B$System Generated Email]( [No] [int] NOT NULL, [To Address] [varchar](250) NOT NULL, [From Address] [varchar](100) NOT NULL, [From Address Title] [varchar](250) NOT NULL, [CC Address] [varchar](250) NOT NULL, [Email Subject] [varchar](MAX) NOT NULL, [Email Body] [varchar](MAX) NOT NULL, [Sent] [tinyint] NOT NULL, [Email Sending Date] [datetime] NOT NULL, [Email Sending Time] [datetime] NOT NULL, CONSTRAINT suppliers_pk PRIMARY KEY (No) ) This table will contains all system generated emails. Now we need to write a SQL Procedure which will create emails from  System Generated Email Table and send through the SQL email profile. Email profile can be found in Database Mail option: SQL code for sending Email: USE msdb GO DECLARE @email_id varchar(250), @from_mail varchar(250), @c...