I am accessing mail body and fetching it in another mail.
But i am not getting original format of previous mail in new mail.
Problem i am facing in this situation are:
Not getting images in destination mail.
Font is also varying.
I am accessing mail body as follows:
NotesRichTextItem rtItem = (NotesRichTextItem)docInbox.GetFirstItem("Body");
String Body = rtItem.GetFormattedText(false , 0);
String bodyFormat = rtItem.type.ToString();
also tried this code:
NotesItem itemBody = docInbox.GetFirstItem("Body");
String bodyFormat = itemBody.type.ToString();
String Body = itemBody.Text;
But not getting solution in both case.
If you're trying to access rich text from Lotus Notes and put it into your own system, that will be very difficult and the NotesAPI is of little help to you. However, if you are trying to copy a rich text item from one NotesDocument to another, look at the AppendRTItem method of the NotesRichTextItem class.
Related
I'm using Microsoft.Office.Interop.Outlook, VB.net and Office 2013 to generate a MailItem, and then send the item to Outlook, show the email window and let the user edit it/send it from Outlook 2013. The main things I'm doing are:
I create the Microsoft.Office.Interop.Outlook.MailItem object and fill it with the relevant information, I generate an HTML constant for the body like this
Private Const mstrHTML_FORMAT As String = "<html><p style='font-size:10pt;font-family:Arial;'>{0}</p></html>"
Then I add the text I want to a string variable strBody and use String.Format to insert the text in the HTMLBody of my object:
objMailItem.HTMLBody = String.Format(mstrHTML_FORMAT, strBody)
I also change the format of the body to HTML:
objMailItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML
After a few other steps I send it to the view
objMailItem.Display(True)
My problem is, when the user sends the email, the receiver will see that the email has a message with the subject as Text
any clue of why this happens?
It's an Outlook "feature". Outlook purposely puts <end> in the message preview when the body isn't long enough to fill the preview.
It's not caused by your code or any bad HTML formatting.
I'm trying to send an Email with an attached PDF file. When I send it to any other mail provider it works just fine, but when I send it to a yahoo email address, the receiver gets a damaged pdf file. The exact message it gives is:
Adobe Reader could not open 'Filename.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).
Because the other email providers were working, I used the following code specifically for yahoo addresses.
if (thisItem.EmailAddress.ToUpper().Contains("YAHOO")){
ContentType contentType = new ContentType();
contentType.CharSet = Encoding.UTF8.WebName;
Attachment theFile = new Attachment(attachmentPath, contentType);
theFile.Name = theFile.Name.Replace("_","");
mm.Attachments.Add(theFile);
}
I've tried a variety of CharSets on the ContentType, hoping that would fix something, no change. I also tried different TransferEncodings on theFile, also no fix. I read somewhere that the file name could cause problems if it had special characters so I removed all the underscores in the name, all that's left is some letters and numbers. I'm not sure what else to try at this point. Any suggestions?
I made a mail sender in C# but I'm having trouble with the body of the mail. It only sends the texts without pictures, links and other elements. Not to mention, I used RichTextBox for that purpose.
So now my question is: what component to use to send mail with pictures, links and else?
I also enabled IsBodyHtml to true.
What I want to do is to copy the pictures, links and texts (with different colors and size) from Microsoft Word and paste it to control, and when user gets mail he gets the exact same body and layout as I send them.
You'll need to send it as html.
Save your word doc as html and use that.
For the images in your document you can either point to them via their absolute urls (publicly available via the internet).
Or you could use the LinkedResource class.
With the LinkedResource class your images have to specify a cid in the source.
var inlineLogo = new LinkedResource("path/myfile.png");
inlineLogo.ContentId = Guid.NewGuid().ToString();
var imageHtmlFragment = string.Format("<img alt='My Logo' src='cid:{0}' style='width: 250px;height: 60px;'/>",inlineLogo.ContentId);
var newMail = new MailMessage();
var view = AlternateView.CreateAlternateViewFromString(imageHtmlFragment, null, "text/html");
view.LinkedResources.Add(inlineLogo);
newMail.AlternateViews.Add(view);
I have a plain text file that I need to read in using C#, manipulate it a bit then I need to email it. That's easy enough, but it also has to stay in the same format as it's original state:
This is an excerpt from a sample file "mySample.txt":
*****************************NB!!!!**********************************
*Please view http://www.sdfsdf.comsdfsdfsdf . *
*********************************************************************
*** DO NOT DELETE or ALTER ANY OF THE FOLLOWING TEXT ***
Company X PTY.
Lorem Ipsum Office
Last Change - 01 February 2008
APPLICATION TO ESTABLISH A COMMUNITY WITHIN
THE RESTIN DISTRICT OF THE IPSUM.
===================================================================
1. COMMUNITY and ACTION
Give the name of the community. This is the name that will be
used in tables and lists associating the community with the name
district and community forum. The community names that are
delegated by Lorem are at the district level
The Action field specifies whether this is a 'N'ew application, an
'U'pdate or a 'R' removal.
1a. Complete community name:**{0}**
1b. Action - [N]ew, [U]pdate, or [R]emoval :**{1}**
As you can see I've got place holders {0} and {1} in the file which is to be replaced by an automated process.
In my C# I'm using a stream reader to read the entire file into a StringBuilder object then replacing the place holders using the StringBuilder.AppendFormat method.
The problem is when I add the text to a email message body and send it the format ends up looking different. It looks like a bunch of spaces or tabs get removed in the process.
private void Submit_Click(object sender, EventArgs e)
{
//create mail client
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add(ConfigurationManager.AppSettings["SubmitToEmail"]);
message.Bcc.Add("xyz#test.com");
message.Subject = "Test Subject";
message.BodyEncoding = Encoding.ASCII;
message.IsBodyHtml = false;
message.Body = _PopulateForm(_GatherInput());//calls method to read the file and replace values
client.Send(message);
//cleanup
client = null;
message.Dispose();
message = null;
}
Anyone have any ideas on how to keep the formatting in tact?
Thanks,
Jacques
The problem you've got is that you're sending plain text as HTML. It's natural that the layout gets changed because HTML is displayed differently than text. Plain text has new lines (\n), tabs (\t), etc., while HTML has line breaks (<BR>) and different layout methods.
If I were you, I would 1st start out by replacing new lines with <BR> (there should be a replace function x.Replace("\n", "<BR>");)
As for the text items that are centered, wrap them in <p style="text-align:center" }>, </p>.
The answer seems to have been with .net and the Mail message object. Instead of adding the content to the Body property, you have to create an alternateView object and add it to that. That solved my problem.
Regards,
Jacques
I want to send a mail with embeded image in ASP.NET
How can i do that?
Regards
Soner
There are generally two ways of doing this, whichever is preferred is up to you.
To literally "embed" the image in the email message itself, you'll want to add it as a Linked Resource and reference the attached resource in the email's HTML.
Alternatively, and more simply, if the image is hosted in a public location then you can just reference that location in the HTML of the email.
Based on the question, it sounds like you are preferring the former approach, but the latter is available as well.
MailAddress sendFrom = new MailAddress(txtFrom.Text);
MailAddress sendTo = new MailAddress(txtTo.Text);
MailMessage myMessage = new MailMessage(sendFrom, sendTo);
MyMessage.Subject = txtSubject.Text;
MyMessage.Body = txtBody.Text;
Attachment attachFile = new Attachment(txtAttachmentPath.Text);
MyMessage.Attachments.Add(attachFile);
SmtpClient emailClient = new SmtpClient(txtSMTPServer.Text);
emailClient.Send(myMessage);
I believe you can either attach the files and refer them, or alternatively, like in regular HTML, embed them encoded in Base64.
You can go through this link
http://www.dotnetspider.com/resources/41465-Send-Formatted-outlook-email-from-NET-C.aspx
Sample project is also attached.
It shows how to put the link of the image in the application in the html template and send emails.