SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Sending E-Mail from SQL 2008 Express


Sending E-Mail from SQL 2008 Express

Author
Message
Gift Peddie
Gift Peddie
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16252 Visits: 14456
clement.degroote (11/22/2010)

Hello.
Sorry, but I don't understand. Could you tell me more ?


Sure so instead of
Imports System.Net 
Imports System.Net.Mail



use the code below instead

Imports System.Net 
Imports System.Net.Mail
Imports System.IO



The later code lets you access the file system or the streams like memory stream which is one of the child classes of the Base Class TextWriter.

Kind regards,
Gift Peddie
clement.degroote
clement.degroote
Grasshopper
Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)Grasshopper (18 reputation)

Group: General Forum Members
Points: 18 Visits: 30
we find issue to our problem. we add content-disposition option on the attachment file property.
See the code below :
If Not strAttachments.Equals(String.Empty) Then
Dim strFile As String
Dim strAttach() As String = strAttachments.Split(";")
For Each strFile In strAttach
Dim Data As Net.Mail.Attachment = New Net.Mail.Attachment(strfile.trim())
Dim Disposition As Net.Mime.ContentDisposition = Data.ContentDisposition
Disposition.CreationDate = System.IO.File.GetCreationTime(strfile.trim())
Disposition.ModificationDate = System.IO.File.GetLastWriteTime(strfile.trim())
Disposition.ReadDate = System.IO.File.GetLastAccessTime(strfile.trim())
Mailmsg.Attachments.Add(Data)
Next
End If
It works well; so thanks a lot to everyone for help.
Very good article and very useful for us.
king regards
Aditya A
Aditya A
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 17
I've tried the mail send as described here. Its working great except for the part where line breaks/carriage returns are removed from the body of the message. The way I've tried it so far is the p_SendEmail procedure is called via my procedure where the body of the message is concatenated(formatted with line breaks). The mail and attachments are recieved but the line breaks generated by my procedure gets removed.
This is how I have generated the linebreaks
SET @MSG ='Dear All,'
SET @MSG=@MSG+CHAR(13)+'Executive : ' +@EXECUTIVE
SET @MSG=@MSG+CHAR(13)
SET @MSG=@MSG+CHAR(13)+'Start Date : ' +CONVERT(VARCHAR(20),@START_DATE,106)
SET @MSG=@MSG+CHAR(13)
SET @MSG=@MSG+CHAR(13)+'End Date : ' +CONVERT(VARCHAR(20),@END_DATE,106)

Finally I pass @MSG as the body of the mail. When the mail is received all the line breaks/carriage returns are absent. Any idea on what's going wrong? The line breaks work properly when I use SQL Db mail.

--Replaced CHAR(13) with < /br>. Works fine
Aditya A
Aditya A
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 17
Any tips on how to make this work with an Open SMTP Server?
jonnylewis
jonnylewis
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 7
Do you think would be an answer for the problem (in sql 2008) where, using database mail to send email and attachments when logged on to sql with sql authentication, won't allow sending the attachment unless one has sysadmin permission?

Here is the books online discussion:
Database Mail uses the Microsoft Windows security context of the current user to control access to files. Therefore, users who are authenticated with SQL Server Authentication cannot attach files using @file_attachments. Windows does not allow SQL Server to provide credentials from a remote computer to another remote computer. Therefore, Database Mail may not be able to attach files from a network share in cases where the command is run from a computer other than the computer that SQL Server runs on.

Have been googling this for days. No one seems to have solution for this problem other than to use windows authentication or give user greater permission, neither of which, is desirable. thanks for any thoughts on this.
APrisk2
APrisk2
SSC Rookie
SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)SSC Rookie (31 reputation)

Group: General Forum Members
Points: 31 Visits: 93
Actually, I wrote an enhanced version that allows for dynamic SMTP servers as well as logging to a SQL table. I'll update the article or send in a new one; should be able to have it out within the next week or so.
Gift Peddie
Gift Peddie
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16252 Visits: 14456
Therefore, users who are authenticated with SQL Server Authentication cannot attach files using @file_attachments. Windows does not allow SQL Server to provide credentials from a remote computer to another remote computer



I don’t think it is related because @file_attachment is local variable in SQL Server not related to system.net used for Microsoft SMTP mail. Please check the link below for the system stored procedure that defines attachment file size and related issues, the reason you can use Default for the connection properties but you still need to talk to system admin and Exchange admin.

http://msdn.microsoft.com/en-us/library/ms191442.aspx

Kind regards,
Gift Peddie
J-LK
J-LK
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 23
Brilliantly simple stuff, many thanks!

This solved an age-old problem for us, and we are highly indebted to people like you that take the time to share your knowledge.

Once again, thanks! :-D
israel.mm
israel.mm
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 17
Thanks
batesview
batesview
SSC-Enthusiastic
SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)SSC-Enthusiastic (152 reputation)

Group: General Forum Members
Points: 152 Visits: 422
<begin>
Dim strRecip As String
Dim strTo() As String = recipients.Split(";")
For Each strRecip In strTo
MailMsg.To.Add(New MailAddress(strRecip))
Next

Instead of looping thru the array have you considered something like String.Join(",", strTo) ?
This allows you to let MS manage the looping and also inserts the comma between names. Since you Split(";") I wonder if it might be easier/quicker to recipients.Replace(";", ",") and thus no need for the array to begin with and you now have a comma separated list that the Address collection is looking for?

Cool function and thanks for a good demo of making a clr function for SQL Server.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search