System.Net.Mail.MailAddress does not allow Gmail GROUP contact - c#

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.

Related

Can not change the display name of From email through smtp.office365.com using C# SmtpClient

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?

How to get all addresses of a recipient in Outlook using .Net/C#

I am trying to get all the email Ids that belong to a person in Outlook. When I look at a contacts properties in Outlook, I can see several email addresses listed - SIM, SMTP and smtp. Is there a way to get all of these? I know how to get the primary email address using:
recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress
which always seem to give the email address marked "SMTP". I want "smtp" and "SIP" email addresses too. This is Outlook 2010 connected to Exchange server and all users are exchange users only.
Thanks in advance
Vikram
Got the answer! Thanks to MethodMan for pointing in the right direction.
const string PR_EMS_AB_PROXY_ADDRESSES = "http://schemas.microsoft.com/mapi/proptag/0x800F101E";
var addresses = recipient.AddressEntry.PropertyAccessor.GetProperty(PR_EMS_AB_PROXY_ADDRESSES);
That gives the list of all available addresses for a contact!

Working with GMail Stars in ActiveUp MailSystem

I'm using ActiveUp MailSystem for an automated mail retrieve and treatment program in C# at work.
In the GMail browser mail cliente, my colleagues use GMail stars to mark a specific mail as handled or to be handled by nother colleague (they all use the same account, but some take care of some subjects while others take care of other subjects, and starring gives them a visual aid into what's taken care off and what's addressed to them by a colleague.
Using the inbox.Fetch.MessageObjectPeekWithGMailExtensions(uid) i can get which messages are starred by looking at msg.HeaderFields["x-gm-labels"] and checking it contains \Starred, however:
1 - How can i find out which start it is set to?
2 - how can i set/change a star on a particular message?
Any help is fully appreciated
I believe the Starred label only indicates that the mail can be found on the Starred mailbox. Gmail uses different IMAP mailboxes for labels. MailSystem isn't fully compatible with Gmail's enhanced IMAP commands yet (doesn't support mail's threadID for example).
You can check if IMAP actually stores the type of star by issuing a command method to the IMAP4Client class, that brings the full message (through the BODY IMAP command), but unfortunately you will have to parse and figure out the meaning of each parameter.
Other solution as Max said is using the X-GM-RAW enhanced search command to check for mails starred with the desired star, in which case you will have to use Gmail's unique identifier to know which email has which star.
Google maps stars to imap \Flagged flag, so you can just manipulate and look for that. Eg, store flag \Flagged, and the message will become starred.

Using custom display name when sending email through EWS

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.

Generate an e-mail to be downloaded by client and sent from their outlook account

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.

Categories