I'm using EWS (Exchange Web Services) with Exchange 2010 to generate and send emails internally within our organization. We currently have a single mailbox/user for which all of our applications send through called app.
Generating emails is no problem, however when a test message is sent, it is received in the recipient's mailbox with the default account name in exchange, regardless of what display name is set in code.
Sample code:
EmailMessage message = new EmailMessage(ExchangeManager.CreateConnection());
// set from address as generic application account
message.From = new EmailAddress("app#company.com");
// set custom display name for sender email
message.From.Name = "Test Display Name";
// set send recipient as myself for testing
message.ToRecipients.Add(new EmailAddress("myaccount#company.com"));
ExchangeManager.SendExchangeMessage(message);
The message is received, however it displays as the app account's default name, rather than "Test Display Name" as used above in code. See screenshot of outlook inbox below:
This type of approach worked fine when using Exchange 2003 STMP services - we could format the address as needed, such as "Intranet Generated Mail ", or "Some Other Application ", etc. Now with Exchange 2010 and EWS it doesn't seem to allow us this option to use a custom display name.
I have also verified through debugging that the display name is being set successfully before the message is sent.
Has anyone successfully used a custom display name with EWS / Exchange 2010?
(Talking in C# terms) Normally the method
EmailAddress()
has an overload where in you can specify the display name:
message.From = new EmailAddress("Custom Display
Name", "app#company.com");
Try the above code & see.
I use EWS, but I've never had to set the Display name manually, because I configured it in Exchange beforehand. In other words, change the Display field of your "app" account in Exchange, and you won't need to manually set it in your program.
Related
I've built an email service using SMTP (System.net.mail nuget package) which also sends out text messages. When I send an email it shows the display name using the following technic:
MailAddress from = new MailAddress("fromEmailId#gmail.com", "DisplayName");
But while sending text messages it doesn't work. It shows the entire email address instead of the display name.
Attached is the snapshot for reference. enter image description here
In the past few months, I used SmtpClient to send emails with host smtp.office.365.comn, and I could change the Display Name of From Email using
message.From = new MailAddress(email, displayName)
But recently the client has found out that they can no longer change that displayName, the mail they received only show email (username#domain.com) in the From
So, is there any change from Microsoft or any way I can custom the Display Name?
Because my code runs well with Gmail (smtp.gmail.com).
I would appreciate any help.
Thanks.
I just ran a test and sent an email from an address inside my organization, and the email message (displayed in Outlook) ignored the Display Name I had set, and instead used the display name that's set in our Active Directory for that account. I then tested with a dummy email address, and it showed the Display Name I had set. Could it be that?
I am using a Gmail business account, say noreply#mycompany.com to send a daily email reports to a few of my clients whose email addresses are from different domains. I use C# to send my email to Gmail's SMTP server.
var receiver = new MailAddress("receiver#domain1.com");
var receiver = new MailAddress("receiver#domain2.com");
var receiver = new MailAddress("receiver#domain3.com");
After a while I found out I had to modify code every time a new customer demands email report. So I want to make a group and maintain that group. Gmail has a Add Group settings in your account's "Contacts" page so I used that to create a group named ReportGroup and added those people. And in the code, this lines throws exception:
var receiver = new MailAddress("ReportGroup");
saying The specified string is not in the form required for an e-mail address.
Well apparently this isn't a legit email address. Is there a way I can bypass this format check? Or is it doesn't make sense to do so?
In further attempts, I tried to name my group as reportgroup#mycompany.com. This time the email got sent without complain however the gmail server rejects the receiver, claiming that
50-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at
550 5.1.1 https://support.google.com/mail/answer/6596 ai2si23882633pad.98 - gsmtp
So this isn't the way to go either. Could any one suggest a solution for me to allow someone non-programmer to maintain an receiver list to which my code sends report to?
Create an alias for your group, and then send email to that address. Then you can continue to maintain the group as you normally do.
I am following this guide and havent got very far
http://www.c-sharpcorner.com/UploadFile/casperboekhoudt/SendingEmailsThroughOutlook12052005000124AM/SendingEmailsThroughOutlook.aspx
I am getting stuck here
Now that we have the MAPI namespace,
we can log on using using:
.Logon(object Profile,
object Password, object ShowDialog,
object NewSession)
Profile: This is a string value that
indicates what MAPI profile to use for
logging on. Set this to null if using
the currently logged on user, or set
to an empty string ("") if you wish to
use the default Outlook Profile.
All i want to do from my programme is take the email address i already have in a variable and open up a new outlook email window with that email address in the too section.
Thanks very much.
This document on CodeProject shows how to open the default mail client.
http://www.codeproject.com/KB/dotnet/Default_mail_client.aspx
Check this list for common Outlook tasks.
I'm using the send attachments
It was quite easy to set up Outlook email capabilities to send reports in one of my apps following the one titled "HOW TO: Use the Microsoft Outlook Object Library to send a message that has attachments by using Visual C# .NET".
Good Luck
One of the requirements for the application that I'm working on is to enable users to submit a debugging report to our helpdesk for fatal errors (much like windows error reporting).
I've been told that e-mails must come from a client's mail account to prevent the helpdesk getting spammed and loads of duplicate calls raised.
In order to achieve this, I'm trying to compose a mail message on the server, complete with a nice message in the body for the helpdesk and the error report as an attachment, then add it to the Response so that the user can download, open and send it.
I've tried, without success, to make use of the Outlook Interoperability Component which is a moot point because I've discovered in the last 6 hours of googling that creating more than a few Application instances is very resource intensive.
If you want the user to send an email client side, I don't see how System.Net.Mail will help you.
You have two options:
mailto:support#domain.com?subject=Error&body=Error message here...
get user to download email in some format, open it in their client and send it
Option 1 will probably break down with complex bodies. With Option 2, you need to find a format that is supported by all mail clients (that your users use).
With option 1, you could store the email details locally on your server against some Error ID and just send the email with an Error ID in the subject:
mailto:support#domain.com?subject=Error 987771 encountered
In one of our applications the user hits the generate button and it creates and opens the email in outlook. All they have to do is hit the send button. The functions is below.
public static void generateEmail(string emailTo, string ccTo, string subject, string body, bool bcc)
{
Outlook.Application objOutlook = new Outlook.Application();
Outlook.MailItem mailItem = (Outlook.MailItem)(objOutlook.CreateItem(OlItemType.olMailItem));
/* Sets the recipient e-mails to be either sent by 'To:' or 'BCC:'
* depending on the boolean called 'bcc' passed. */
if (!(bcc))
{
mailItem.To = emailTo;
}
else
{
mailItem.BCC = emailTo;
}
mailItem.CC = ccTo;
mailItem.Subject = subject;
mailItem.Body = body;
mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
mailItem.Display(mailItem);
}
As you can see it is outputting the email in plaintext at the moment because it was required to be blackberry friendly. You can easily change the format to HTML or richtext if you want some formatting options. For HTML use mailItem.HTMLBody
Hope this helps.
EDIT:
I should note that this is used in a C# Application and that it is referencing Microsoft.Office.Core and using Outlook in the Email class the function is located in.
The simple answer is that what you are trying to achieve isn't realistically achievable across all platforms and mail clients. When asked to do the improbable it is wise to come up with an alternative and suggest that.
Assuming that your fault report is only accessible from an error page then you've already got a barrier to spam - unless the spammers can force an exception.
I've always handled this by logging the fault and text into the database and integrating that with a ticketing system. Maybe also have a mailto: as Bruce suggest with subject=ID&body=text to allow the user to send something by email.
I don't think an .eml format file will help either - because they'll need to forward it, and most users would probably get confused.
A .eml is effectively plain text of the message including headers as per RFC-5322.