In this post, I will tell you about sending SharePoint List Item Attachments in Email Programatically. When you ought to send email and attachment with it then its simple task, when attachment file is lying on your file system. But, once Attachment is as URL format, then its somewhat problem , as directly ULR formats don’t seem to be supported. during this case you’ve got to go by Steam param method for Attachment.
We need to use WebClient class for a similar. with UseDefaultCredentials property set as true. Otherwise you’ll get error 401 (Un-Authorized). On the below code, you’ll be able to direcly call this method.
public static void SendMailWithAttachment(SPWeb web, string toAddress, string ccAddress, string subject, string body,SPListItem Itemattachment)
MailMessage objEmail = new MailMessage();
MailAddress mailFrom = null;
SmtpClient smtp = null;
SPWebApplication webapp = web.Site.WebApplication;
mailFrom = new MailAddress("[email protected]", "Admin");
objEmail.From = mailFrom;
// if toAddress Contains many email addresses seperated by ','
string tos = toAddress.Split(',');
for (int i = 0; i < tos.Length; i++)
// if ccAddress Contains many email addresses seperated by ','
string ccs = ccAddress.Split(',');
for (int i = 0; i < ccs.Length; i++)
objEmail.Body = body;
objEmail.Subject = subject;
objEmail.IsBodyHtml = true;
//Adding Attachments to the Email, Itemattachment is SPListItem which contains Attachments
foreach (string fileName in Itemattachment.Attachments)
string attachPath= Itemattachment.Attachments.UrlPrefix + fileName;
WebClient webAttach = new WebClient();
webAttach.UseDefaultCredentials = true;
var stream = webAttach.OpenRead(attachPath);
Attachment attached = new Attachment(stream, fileName);
smtp = new SmtpClient();
smtp.Host = webapp.OutboundMailServiceInstance.Server.Address;
Top 3 SharePoint 2013 Hosting Recommendation
The price of HostForLIFE.eu SharePoint 2013 hosting packages is quite competitive, especially the Level 1 which we may recommend most here. The Level 1 hosting package is €9.99/mo. It include 50GB bandwidth, 5 GB disk storage, MSSQL 2014 databases, MySQL databases, Unlimited Subsites and support almost all of the cutting-edge Windows technologies, such as remote IIS management, ASP.NET v5 and Full Trust. Hosting a Windows-based website with HostForL.eu should be absolutely worry-free.
ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers SharePoint 2013 hosting starts from $9,99/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable SharePoint 2013 Hosting, ASPHostPortal.com should be your best choice.
DiscountService.com.au is Microsoft Gold Partner, which means they will be the first one to know the latest Microsoft technology and test Microsoft product before being released to the public. With tons of positive feedback from their customers, we are glad to grant them as the Best SharePoint 2013 Hosting of this month. Their SharePoint hosting is sold at $10/month only, each account is allocated with large Bandwith and Storage Space.