views:

237

answers:

1

Currently I'm sending E-Mail messages by SPUtility.SendMail. I'd like to embed images into my message so i can give it a little bit style (div backgrounds, logo images etc.).

Is this possible?

P.S. I can't give direct URL addresses to image SRCs because the resources are located in a site which belongs to a private network which requires authentication for accessing to the files.

Edit:

I did some research before asking here, ofcourse the first thing i encountered was the System.Net.Mail (do you know that there is a whole web site devoted to it). But the Sharepoint Deployment team in my client's company has some strict rules about custom coding. They have coding guide lines and everything. I'm trying to stick with the SP SDK as hard as i can.

+4  A: 

The most straighforward way for me has been through using System.Net.Mail, since you can inline your own content.

Here's a sample usage

using (MailMessage msg = new MailMessage("fromaddress", "toaddress"))
{
    msg.Subject = "subject";
    msg.Body = "content";
    msg.IsBodyHtml = true;

    SmtpClient smtp = new SmtpClient("smtp server name");
    smtp.Send(msg);
}

Same concept applies to using SPUtility.SendMail (aside from the fact that you'll need a reference to your SPWeb:

From http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.sendemail.aspx

try
{  
    SPWeb thisWeb = SPControl.GetContextWeb(Context);  
    string toField = "[email protected]";  
    string subject = "Test Message";  
    string body = "Message sent from SharePoint";  
    bool success = SPUtility.SendEmail(thisWeb,true, false, toField, subject, body);
}
catch (Exception ex)
{  
    // handle exception
}

The second boolean parameter in SendMail is false to disable HTML encoding, so you can use your <img > and <div > tags in the message body.

Gurdas Nijor
Thank you for replying. I did some research before asking here, ofcourse the first thing i encountered was the System.Net.Mail (do you know that there is a whole web site devoted to it). But the Sharepoint Deployment team in my client's company has some strict rules about custom coding. They have coding guide lines and everything. I'm trying to stick with the SP SDK as hard as i can.
frbry
Added to my answer above.
Gurdas Nijor