Hi I have a new requirement. How can I send a newsletter in the body content in a mail .
The newsletter is made from Microsoft Publisher application.
Kindly let me know if you need more info.
Thanks
Hi I have a new requirement. How can I send a newsletter in the body content in a mail .
The newsletter is made from Microsoft Publisher application.
Kindly let me know if you need more info.
Thanks
To send email in .NET, use the SmtpClient and MailMessage and Attachment classes.
The MailMessage class represents the content of a mail message. The SmtpClient class transmits email to the SMTP host that you designate for mail delivery. You can create mail attachments using the Attachment class.
Assuming you have a HTML newsletter with a separate stylesheet and images, you would need to create a MailMessage with HTML body content and add the external files as attachments. You will need to set the ContentId
property of each attachments, and update the references in the HTML to use this.
A href in the body HTML to an attachment uses the cid: scheme. For an attachment with id "xyzzy", the href is "cid:xyzzy".
To construct an MailMessage with a HTML body:
string content; // this should contain HTML
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"[email protected]",
"[email protected]");
message.Subject = "The subject.";
message.Body = content;
message.IsBodyHtml = true;
To construct an MailMessage with an attachment:
string file = "data.xls";
// Create a message and set up the recipients.
MailMessage message = new MailMessage(
"[email protected]",
"[email protected]");
message.Subject = "The subject.";
message.Body = "See the attached file";
// Create the file attachment for this e-mail message.
Attachment data = new Attachment(file, MediaTypeNames.Application.Octet);
data.ContentId = Guid.NewGuid().ToString();
// Add time stamp iformation for the file.
ContentDisposition disposition = data.ContentDisposition;
disposition.CreationDate = System.IO.File.GetCreationTime(file);
disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
// Add the file attachment to this e-mail message.
message.Attachments.Add(data);
To send a MailMessage with SmtpClient:
//Send the message.
SmtpClient client = new SmtpClient(server);
// Add credentials if the SMTP server requires them.
client.Credentials = CredentialCache.DefaultNetworkCredentials;
client.Send(message);
Lachlan Roche has an excellent answer. I would just add that you might think about outputting the newsletter to Adobe Acrobat, or an image file, or html.
Most people targeted by the newsletter probably will not have Publisher installed. so sending them the .pub file might not have the desired effect.
I presume your client wishes to be able to envoke a Macro or Office App inside of Publisher to send the newsletter they have composed as an email to list of people.
Lachlans code will let you send the email, I am suggesting adding a step to export the newsletter to a more universal format. I am sure you can leverage built in functions in Publisher from your code for the export.