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 «««23456»»

Sending E-Mail from SQL 2008 Express Expand / Collapse
Author
Message
Posted Monday, November 22, 2010 8:02 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, November 13, 2014 2:52 PM
Points: 3,428, Visits: 14,451
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
Post #1024358
Posted Tuesday, November 23, 2010 10:51 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, May 5, 2011 7:31 AM
Points: 6, 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

Post #1025332
Posted Monday, December 20, 2010 2:08 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, June 22, 2012 3:59 AM
Points: 2, 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
Post #1037074
Posted Wednesday, February 9, 2011 10:28 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, June 22, 2012 3:59 AM
Points: 2, Visits: 17
Any tips on how to make this work with an Open SMTP Server?
Post #1061697
Posted Monday, February 20, 2012 12:17 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, March 20, 2012 1:49 PM
Points: 1, 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.
Post #1254868
Posted Monday, February 20, 2012 1:35 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 11:27 AM
Points: 5, Visits: 78
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.
Post #1254906
Posted Monday, February 20, 2012 1:53 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Thursday, November 13, 2014 2:52 PM
Points: 3,428, Visits: 14,451
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
Post #1254913
Posted Wednesday, July 18, 2012 5:30 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Saturday, January 11, 2014 11:32 PM
Points: 10, 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!
Post #1331380
Posted Friday, July 12, 2013 1:08 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, November 14, 2013 7:28 AM
Points: 1, Visits: 15
Thanks
Post #1472877
Posted Friday, July 12, 2013 9:19 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, November 13, 2014 6:03 AM
Points: 30, Visits: 404
<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.
Post #1473099
« Prev Topic | Next Topic »

Add to briefcase «««23456»»

Permissions Expand / Collapse