Im using mailKit in asp mvc core to collect email from a IMAP mailbox.
I return the message using the command
var message = inbox.GetMessage(uid)
This returns all the results of the message. From here i want to access the sender email address (not including the name). After breakpointing on the above line i can see that the variable message has the following property
message
-From
--From(Array)
---From(item)
----Name (name of the sender)
----Address(email of the sender)
When referencing the above above using the message i am able to receive the name, however the address is not listed (within intelisence, nor will it build)
var name = message.From[0].Name.ToString()
Does anyone know why this would be visible as properties of the variable but not accessible via the code?
i simply want to
var name = message.From[0].Name.ToString()
The MimeMessage.From property is a InternetAddressList (more-or-less List<InternetAddress>).
InternetAddress is an abstract base class for MailboxAddress and GroupAddress which only contains a Name property as you've discovered.
In order to get the Address, you first need to cast it to a MailboxAddress... but only if it is actually a MailboxAddress or you'll get a cast exception.
InternetAddressList has a convenience property called Mailboxes which can be used to iterate over a flattened list of the MailboxAddresses contained within.
You can use this code block.
message.From.OfType<MailboxAddress>().Single().Address;
Another solution:
message.From.Mailboxes.Single().Address;
I want to change my email display name which is sent by my MVC application.
actually, the email address is: sample#company.com
the default display name is: Company Sample.
Now i want to change that display name into "SomeOne" but it not works. i have tried below items,
Tried Email display name property:
MailAddress from = new MailAddress("sample#company.com", "SomeOne");
It works fine in Gmail but in outlook, the display name not changed.
MailAddress from = new MailAddress("sample#company.com", "\\SomeOne\\");
It will change the display name in outlook but double quote(") added at the last like this
SomeOne"
objMail.From = new MailAddress("<DisplayName>EmailAddress#domain.com");
Not works.
Can you please provide any suggestions..?
Thanks,
Nagaraj M
Your first address is correct
MailAddress from = new MailAddress("sample#company.com", "SomeOne");
And I believe the third is backwards
//objMail.From = new MailAddress("<DisplayName>EmailAddress#domain.com");
objMail.From = new MailAddress("DisplayName<EmailAddress#domain.com>");
Outlook presents other challenges. If the address is in your Outlook contacts it may overwrite the friendly address coming in. Same if you are sending from Outlook to a previous friendly address. In most cases clearing out the Most Recently Used (MRU) cache will take care of it. There are a few ways of doing this, some require working with the registry to find the location of the actual file
Clearing Outlook Most Recently Used Lists
your first address is correc
When ever I create a meeting in Outlook, Subject field for an appointment is going through incorrectly. Instead of something like "Test" I get the name of the user who created an appointment.
-> bold = title, admin = creator name
-> admin = creator name even though it suppose to be subject.
foreach (Appointment a in room.appointments)
m.Subject = a.Subject
Is this a known issue; Is there another field that is responsible for subject?
This is actually not an "issue" but a "feature" of Exchange's workflow for meeting invites. The default on a room resource is to replace the subject with the orgranizer. This can be changed for a room with a PowerShell command:
Set-Calendarprocessing -Identity:roommb -AddOrganizerToSubject:$false -DeleteSubject:$false
Of course you need proper permissions to do this, or else bribe your Exchange admin!
I’m trying to create an event in my Microsoft Outlook calendar by using iCalendar standard. I’ve sent an email with content type “text/calendar” to my Exchange mailbox from .NET application.
It arrives to Outlook as an meeting request. Everything looks good, till the moment when I click the received meeting request, Outlook displays it as an empty calendar view with the text: “Meeting cannot be found in the calendar”.
I don’t understand why – I wanted to create an event and it is trying to find some existing?
If I send exactly the same email to whoever participant of the meeting except the organizer, it creates an event in their calendars and everything seems to be ok.
I’ve found that it is caused by the “ORGANIZER” property. If it is set to organizer’s email (my email) and I send meeting request to myself, an event is not created with the information “Meeting cannot be found in the calendar”.
So the question is why it doesn’t create an event for organizer? Organizer must have that event created to be notified by other participants if they have accepted or cancelled the meeting.
Here is the iCalendar:
BEGIN:VCALENDAR
PRODID:-//Company//Product 3.0//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
DTSTART:20130225T200000Z
DTEND:20130225T203000Z
DTSTAMP:20130225T143039Z
ORGANIZER;CN="John Doe":mailto:john.doe#domain.com
UID:20130225T143039Z#domain.com
ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;RSVP=TRUE;CN="John Smith"
;X-NUM-GUESTS=0:mailto:john.smith#domain.com
CLASS:PUBLIC
CREATED:20130225T143039Z
DESCRIPTION:
LAST-MODIFIED:20130225T143039Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Booking test
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
Let’s say that organizer want to create an meeting for 2 attendees. He fills in a form in the booking system.
The booking system sends email containing iCalendar standard to himself and to 2 meeting attendees.
This scenario doesn’t work.
It is not possible to create an event (cancellable meeting object) in the calendar of the organizer. The client thinks that email containing iCalendar format is just notification for attendee of the meeting already created in the organizer calendar. If such an email arrives to organizer’s mailbox, client app doesn’t create an event in the organizer’s calendar. It assumes that an event was created by organizer himself. E.g.: Outlook tells you in that case that “Meeting cannot be found in the calendar”.
If you ask Microsoft support about it, they only tell you that they does not support open standards: http://support.microsoft.com/kb/2269506
Working solution to this problem is to use platform services (Exchange Web Services or Google Calendar API) to create an event in the organizer’s calendar. Forget iCalendar standard.
The services can be configured for sending notifications to attendees automatically.
So it is enough to pass “SendInvitationsMode.SendToAllAndSaveCopy” if you’re using EWS:
Appointment appointment = new Appointment(service);
appointment.Subject = "Status Meeting";
appointment.Body = "The purpose of this meeting is to discuss status.";
appointment.Start = new DateTime(2014, 3, 1, 9, 0, 0);
appointment.End = appointment.Start.AddHours(2);
appointment.Location = "Conf Room";
appointment.RequiredAttendees.Add("user1#contoso.com");
appointment.RequiredAttendees.Add("user2#contoso.com");
appointment.OptionalAttendees.Add("user3#contoso.com");
appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
or set “sendNotifications” parameter to true in case of Google Calendar API.
You don’t need to send an email to every particular attendee.
This is a bit of an old issue, but i think it is caused from using
METHOD:REQUEST
This marks that the ical should be updated, not that it is a new item. Instead, use
METHOD:PUBLISH
I can confirm that this works with DDay.iCal and Outlook Calendars.
This drove me mad for a week, so it is nice to see someone else confirming what I suspected. There is actually a relatively simple solution, which solves the question, although it is not very elegant. I can understand why one would not be allowed to take the role of Organiser from an outside source, but it is annoying that you can't.
Send out 2 invites. One to yourself (or whoever the organiser is) and then a different one to everyone else.
The one to yourself should have something else other than you down as the ORGANSISER, e.g. ORGANIZER:donotreply#outlook.com
The one to everyone else should have your email down as the organizer.
For this approach to work, you should set METHOD:REQUEST. If you set it to PUBLISH you will get duplicates on updates.
This approach means you get the meeting in your diary and you also get replies (to get replies you need to include the following line for each attendee:
ATTENDEE;CN="The Name";RSVP=TRUE:mailto:the_email#address.com.)
Note that the UID is the same for both versions of the file. It helps if the ORGANISER gets the Invite first so they can accept it before they start getting replies, otherwise people will be replying to something that effectively does not yet exist. That wont stop them accepting the invite, but it might be a little confusing for the ORGANIZER. To help with this I put in a slight delay between email 1 and 2.
I would assume that your problem is because Exchange assumes that the organizer of the event is also the originator of the event. Which seems fair enough, as otherwise it would be child's play to send meetings to people making them the organizer and they would be added automatically to the person's calendar.
All that said, no idea how to get around the issue.
the behavior of event invitation being sent by email is described in rfc6047 which further extends the icalendar RFC (RFC5545).
section 2 and section 3 on security, summarizes two spoofing threats:
spoofing the "Organizer", and spoofing an "Attendee"
that is
spoof#xyz.example.net is not allowed to modify or cancel a meeting that was organized by a#example.com.
to your case:
did you send the invitation from the same email address as your exchange (talking about the From: in the mail not the Organizer:mailto ? if not it might be worth trying to send it via the exchange address.
should above not work, to address your need for the organizer to have the invitation in its calendar you probably will need to add it programmatically in the organizer's agenda as it is likely that the CUA (Calendar User Agent) or Exchange does not allow a 3rd party mailer to add events in agenda without end-user UI usage.
In recent months ,our service also meet the same problem as you:
our service create meeting calendar for organizer and attendees,
if attendees contains organizer ,organizer (as a atteendee) can get a calendar email,
but it does neither be allowed to receive/reject the meeting(the button is disabled) nor see it in calendar(no calendar event).
finally, I notice that only when under following condition this will happen:
1. mail.From = organizer
2. Ateendees.contains(organizer) //case-insensitive.
So , I simply change my code to follwing , and it works fine for all attendees (include organizer):
if (!attendeeEmail.ToLower().Contains(organizer.Address.ToLower()))
{
message.From = organizer;
}
else
{
//such as your actual email sender, in our case, our mail sender use another email,
//say ActualSender,and if leave empty, then our mail sender will fill as:
message.From = ActualSenderEmail;
}
I need to send email with attachment. No problem if I do it by myself, but...
Inside the company I work for, I need to pass through a web service awaiting an email and a body.
I know that the implementation of this service use System.Web.mail.Mailmessage doing probably something like this:
MailMessage mm = new MailMessage();
mm.to = email_;
mm.body = body_;
...
So, is there a way to create a string that'll contain my attachement so I can send it to the web service ?
thx.
--Edition--
I must use a class "TheCompanyMail" that has 2 properties (to,body) and one method (send). This class is a proxy to a webservice. This webservice is the one that really sends the mail.
The problem is that I need to add an attachement to the mail and really don't know how to do it.
Example
File f = MyFuturAttachementFile;
TheComapyMail m = new TheCompanyMail();
m.to = "myCustomer#Company.com"
m.body = "Here is the file you're waiting for:"+f.ToString(); //this of course doesn't work !!!
m.send();
So I'm wondering if I can format the string of the body property to add attachement ?
I'm not sure if I'm right, but in my opinion there is no way to pass attachments by adding them in a string to message body. The main why-not argument is safety. I don't think that Microsoft could allow this class to behave like this...
You can't do it that way, you need to add it to the Attachements property of the MailMessage.
Why don't you store the file somewhere else where they can access it and just send them a link to it instead?
You could create an Html email where the "attachment" is actually link to download the file rather than an actual email attachement.