I'm wondering how to send meeting request to allow GMail correctly recognize it?
If you try to send iCalendar meeting request definition given bellow as an alternative view using habitual code (also given bellow) via MailMessage object to GMail it will be resulted in not recognized meeting request:
But the mail with exactly the same meeting request sent via GMail UI results in recognized meeting request! Puzzling.
Does anybody know what "magic" I'm missing?
Good to notice that Outlook correctly recognizes exactly the same meeting request sent by given code.
The code to send mail with meeting request:
class Program
{
static string From = "sender#example.com";
static string TimeFormat = "yyyyMMdd\\THHmmss\\Z";
static string To = "target#example.dom";
static void Main(string[] args)
{
string content = ReadFile("event-template.ics");
content = content.Replace("#TO#", To);
content = content.Replace("#FROM#", From);
content = content.Replace("#UID#", Guid.NewGuid().ToString().Replace("-", ""));
content = content.Replace("#CREATED-AT#", DateTime.UtcNow.AddDays(-1).ToString(TimeFormat));
content = content.Replace("#DTSTART#", DateTime.UtcNow.AddDays(1).ToString(TimeFormat));
content = content.Replace("#DTEND#", DateTime.UtcNow.AddDays(1).AddHours(1).ToString(TimeFormat));
MailMessage message = new MailMessage();
message.From = new MailAddress(From);
message.To.Add(new MailAddress(To));
message.Subject = "Meeting Request from Code!";
var iCalendarContentType = new ContentType("text/calendar; method=REQUEST");
var calendarView = AlternateView.CreateAlternateViewFromString(content, iCalendarContentType);
calendarView.TransferEncoding = TransferEncoding.SevenBit;
message.AlternateViews.Add(calendarView);
using (var smtp = new SmtpClient())
{
smtp.Send(message);
}
}
public static string ReadFile(string fileName)
{
using (StreamReader r = new StreamReader(fileName))
{
return r.ReadToEnd();
}
}
}
iCalendar template definition:
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//A//B//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
ORGANIZER;CN="Organizer":mailto:#FROM#
ATTENDEE;CN="Attendee";CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=
NEEDS-ACTION;RSVP=TRUE:mailto:#TO#
DTSTART:#DTSTART#
DTEND:#DTEND#
LOCATION:Location test
TRANSP:OPAQUE
SEQUENCE:0
UID:#UID#
DTSTAMP:#CREATED-AT#
CREATED:#CREATED-AT#
LAST-MODIFIED:#CREATED-AT#
DESCRIPTION:Test description\n
PRIORITY:5
CLASS:PUBLIC
END:VEVENT
END:VCALENDAR
UPD. The source of email generated by code and received by GMail (not recognized by GMail as a meeting request): http://pastebin.com/MCU6P16Y.
The source of email composed by GMail during forwarding (recognized correclty): http://pastebin.com/zfbbj9Gg
IMPORTANT UPDATE. Just changing target from my email (<my>#gmail.com) to my colleague's one (<colleague>#gmail.com) and it starts to recognize properly! Now it definitely looks like GMail issue.
(I'm sending email from the address that differs from target, sure)
UPDATE. Found exactly the same issue in GMail support forum: Bug: Gmail fails to recognize .ics calendar invitations attached to incoming messages. The issue dated by Jun, 2011 and reported as fixed to Jul, 2011. I've created new topic there: GMail fails to recognize *.ics attachment as a meeting request.
It seems that the problem is not with GMAIL recognizing the meeting request, but with problems displaying it. I was bugged by the same problem.
It was "fixed" after I changed GMAIL display language to "English (US)" from Settings menu.
So it is definitely a bug.
If you're using c# I managed to get this working outlook web, gmail, outlook 2016.
What it appears you need to do is add an alternate view, this doesn't appear to work when you have multiple views but does work for your example above.
The alternative view below:
var ct = new ContentType("text/calendar");
if (ct.Parameters != null)
{
ct.Parameters.Add("method", "REQUEST");
ct.Parameters.Add("charSet", "utf-8");
var avCal = AlternateView.CreateAlternateViewFromString(calendarAppt.ToString(), ct);
avCal.TransferEncoding = TransferEncoding.Base64;
mail.AlternateViews.Add(avCal);
}
Related
In an ASP/C# application I'm sending an email with 3 file attached. The 3 files are the same type, same extension and more or less same size ( but none are empty ).
The email is sent correctly. If I open it using outlook, I have no problems. I can see the body, and the 3 files attached.
But here is my issue: If I send that mail to a Gmail Adress, then on Gmail I can see only 2 attachments.
And if I click on the download all attachment icon ( on the right ), it will download the 2 visible attachment + the third one but empty.
It's a really weird issue.
Also there is a 4th attachment which is an embedded image. And this image is display correctly in the mail body.
Here is the code I'm using to send the mail:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("SMTP_IP_ADRESS", SMTP_IP_PORT);
mail.From = new MailAddress("MYEMAIL#DOMAIN.COM");
mail.To.Add("GMAIL_EMAIL");
mail.To.Add("OUTLOOK_EMAIL");
mail.Subject = "MSN "+Request.Params["nameMsn"];
Attachment imageAttachment = new
Attachment(Server.MapPath(Url.Content("~/Content/images/image.png")));
string contentID = "logoCare";
imageAttachment.ContentId = contentID;
mail.IsBodyHtml = true;
mail.Body = "<html><body>Have a good day.<br/>Best regards. <br/><br/><img width='200'
src=\"cid:"
+ contentID + "\"></body></html>";
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFileBase file = Request.Files[i];
var attachment = new Attachment(file.InputStream, file.FileName,
MediaTypeNames.Application.Octet);
mail.Attachments.Add(attachment);
}
mail.Attachments.Add(imageAttachment);
SmtpServer.Send(mail);
The third attachment you see empty can possibly be the CID embedded image that web based email clients (like Gmail) can't manage, meanwhile it works with desktop email clients like Outlook. Can you verify this?
Please take a look at here
In my program, I am reading an Exchange mailbox using EWS .NET API and forwarding the emails as attachment to an external email address. Code that I have used is below
private void ForwardMessage(ExchangeService exchangeService, EmailMessage item)
{
ResponseMessage responseMessage = item.CreateForward();
item.Load(new PropertySet(BasePropertySet.FirstClassProperties, new
PropertySet(){ItemSchema.MimeContent,
ItemSchema.Subject}));
var mail = new EmailMessage(exchangeService);
var attachment = mail.Attachments.AddFileAttachment(String.Format("
{0}.eml", item.Subject),
item.MimeContent.Content);
String forwardEmailAddresses =
MailProcessorSettings.Default.ForwardEmailAddress;
char[] delimiters = { ',', ';' };
foreach (var emailAddress in forwardEmailAddresses.Split(delimiters,
StringSplitOptions.RemoveEmptyEntries))
{
mail.ToRecipients.Add(emailAddress);
}
mail.Subject = item.Subject;
mail.Send();
}
I am able to open the email forwarded as attachment in Outlook. However, if I send it to Gmail or to other users using different email clients it shows up as a blank attachment.
How do I ensure that the email forwarded as an attachment preserves the original content?
Adding a line indicating the content type of the message seems to fix this issue. Either of the following settings seems to work. After adding the ContentType, I was able to download the attachment from Gmail although I had to use the Outlook Client to open it.
attachment.ContentType = "multipart/alternative"
OR
attachment.ContentType = "message/rfc822"
Following C# code in VS2017 shows the mail was sent successfully. And I can verify from my outlook account's sent box that the email indeed was sent successfully. But on my Yahoo account, email is not there even after more than an hour. Question: Is something missing in my code here - how can we make it work? NOTE: I've verified in my outlook's sent box that both From and To mail addresses are correct. I'm following this Technet article.
static void Main(string[] args)
{
try
{
//From Address
string FromAddress = "myfromEmail#hotmail.com";
string FromAdressTitle = "Email from ASP.NET Core 1.1";
//To Address
string ToAddress = "myToEmail#yahoo.com";
string ToAdressTitle = "Microsoft ASP.NET Core";
string Subject = "Hello World - Sending email using ASP.NET Core 1.1";
string BodyContent = "ASP.NET Core was previously called ASP.NET 5. It was renamed in January 2016. It supports cross-platform frameworks ( Windows, Linux, Mac ) for building modern cloud-based internet-connected applications like IOT, web apps, and mobile back-end.";
//Smtp Server
string SmtpServer = "smtp.live.com";
//Smtp Port Number
int SmtpPortNumber = 587;
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress(FromAdressTitle, FromAddress));
mimeMessage.To.Add(new MailboxAddress(ToAdressTitle, ToAddress));
mimeMessage.Subject = Subject;
mimeMessage.Body = new TextPart("plain")
{
Text = BodyContent
};
using (var client = new SmtpClient())
{
client.Connect(SmtpServer, SmtpPortNumber, false);
// Note: only needed if the SMTP server requires authentication
// Error 5.5.1 Authentication
client.Authenticate(FromAddress, "myFromEmailpassword");
client.Send(mimeMessage);
Console.WriteLine("The mail has been sent successfully !!");
Console.ReadLine();
client.Disconnect(true);
}
}
catch (Exception ex)
{
throw ex;
}
}
Finally, after an hour, I received the email on my yahoo account. Not sure why it took more than an hour for yahoo but outlook sent it right away. Thanks to those who may have tried to help but probably did not find an error in the code.
Observation: In the received email I can see, in the To field the ToAdressTitle as Microsoft ASP.NET Core (as expected from the code above). But in the From field I see only the FromAddress and not the FromAdressTitle as Email from ASP.NET Core 1.1 (shown in the code above). I wonder why?
How do I find out "Out Of Office" flag from a received email using C#.
I dont have any scope to parse the Subject / Body. I need to find only thru either the header property if available. Or any other means.
Please suggest.
Thanks,
Sriram
You can add the custom header to the mailMessage as below,
MailMessage mail = new MailMessage();
mail.To = "me#mycompany.com";
mail.From = "you#yourcompany.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body.";
mail.Headers.Add( "X-Organization", "My Company LLC" );//Your custom header goes here
SmtpMail.SmtpServer = "localhost"; //your real server goes here
SmtpMail.Send( mail );
and letter you can access it as below,
IEnumerable<string> headerValues = mail.Headers.GetValues("X-Organization");
var id = headerValues.FirstOrDefault();
If you are using Outlook Object Model, check if the MailItem.MessageClass property is "IPM.Note.Rules.OofTemplate.Microsoft". This will only work if the sender is in the same domain as the receiver. Otherwise all bets are off - this is nothing special about the OOF messages.
When i send a email from my site to Uniform http://co.za registrar and cc myself in the mail i get an email returned from them that they received the email, but cannot find some of the information as it has those funny characters added to it. I saw that there was a previous post on the site but none of the answers seem to work for me, and i tried alot of post and blog on google.
The entire body of the email is constructed of the template you get from the registrar site and i used etc as the detail i need to populate and replace those, then send the body of the email off to the registrar.
EX:
1a. Complete domain name: < domainname >
gets replaces with the domain name exmaple.co.za
My Code:
MailMessage emailmsg = new MailMessage("myemail#domain.co.za", "coza-admin#co.za");
emailmsg.Subject = "N domain domain.co.za";
emailmsg.Bcc.Add("myemail#domain.co.za");
emailmsg.Body = Body;
emailmsg.IsBodyHtml = false;
var plainView = AlternateView.CreateAlternateViewFromString(Body, new ContentType("text/plain; charset=iso-8859-1"));
plainView.TransferEncoding = TransferEncoding.SevenBit;
emailmsg.AlternateViews.Add(plainView);
SmtpClient sSmtp = new SmtpClient();
sSmtp.Send(emailmsg);
This code send a bcc copy to myself and from the looks of it through outlook all seems fine and i should be but when they receive it the characters gets added. it seems to randomly add those characters. then obviously the request fails as the seconds name server cannot be found.
Returned Email:
Administrative Info
Contact: Administrator=0D=0A 4b. Title/posi= (Administrator)
Company: CompanyName Ltd
Postal: P.O Box 12841, Centrahill, 6006
Phone: +27.00000000=0D=0A 4f. Fax Number: +27.00000000=
Provided Nameserver information
Primary Server : ns1.nameserver.co.za
Secondary 1 : ns2.nameserver.co.za=0d=0a,
Any help would be appreciated.
note: the registrar requires the the email be in plain text and not base64 or html whatsoever as their system picks up plain/text email and faxes and automatically processes them.
Thanks
I figured it out, changed my code to the following:
MailMessage emailmsg = new MailMessage("from#address.co.za", "to#address.co.za")
emailmsg.Subject = "Subject";
emailmsg.IsBodyHtml = false;
emailmsg.ReplyToList.Add("from#address.co.za");
emailmsg.BodyEncoding = System.Text.Encoding.UTF8;
emailmsg.HeadersEncoding = System.Text.Encoding.UTF8;
emailmsg.SubjectEncoding = System.Text.Encoding.UTF8;
emailmsg.Body = null;
var plainView = AlternateView.CreateAlternateViewFromString(EmailBody, emailmsg.BodyEncoding, "text/plain");
plainView.TransferEncoding = TransferEncoding.SevenBit;
emailmsg.AlternateViews.Add(plainView);
SmtpClient sSmtp = new SmtpClient();
sSmtp.Send(emailmsg);
All characters spaces are kept like they should be in the email template.
Hope this will help someone aswell.
=OD=OA is quoted-printable representation of CrLf.
If you want to use the iso-8859-1 characterset, then you will want to get rid of this line:
plainView.TransferEncoding = TransferEncoding.SevenBit;
If you insist on using 7 bit encoding, then you can only use ASCII characters in your email, so change the is0-8859-1 characterset to "us-ascii"