0 votes
by (250 points)
edited

Hi,

I'm using MailMessage in the following way:

  • We have a web application that creates a MailMessage server-side
  • These MailMessage gets saved in the Outlook format (MailFormat.OutlookMsg)
  • The saved MailMessage gets streamed to the client for opening in Outlook (2003 in my current test setup)

This works fine. Now I've been asked to implement a feature where an optional From-address can be added to the MailMessage during creation. This in itself works: the email address (and optionally display name) indeed get pre-filled for the message when it is opened on the client.

However, it is impossible to send the message once opened in Outlook. The error message is the following (translated into English): "You do not have the permission to send this message on behalf of the specified user". While this message is clear, unfortunately that appears not to be the problem. When I remove the pre-filled email address and manually type in the exact same address, I am able to send the message, indicating I indeed do have permission to send on behalf of it.

The Outlook 2003 client uses Exchange 2010, and the user from which it is sent is authorized to send with the email address I supply.

Any help in this matter would be appreciated.

Edit: below is the code that generates the message.

  Public Shared Sub SaveEmailMessage(ByVal InternalFileName As String, ByVal Message As Net.Mail.MailMessage)

     Dim RebexMessage As New MailMessage
     If Not Message.[From] Is Nothing Then
        RebexMessage.From = New MailAddressCollection(Message.From.Address)
     End If
     For Each MailAddress As Net.Mail.MailAddress In Message.To
        RebexMessage.To.Add(MailAddress.Address)
     Next
     For Each MailAddress As Net.Mail.MailAddress In Message.CC
        RebexMessage.CC.Add(MailAddress.Address)
     Next
     For Each Attachment As Net.Mail.Attachment In Message.Attachments
        Dim Att As New Rebex.Mail.Attachment(Attachment.ContentStream, Attachment.Name)
        RebexMessage.Attachments.Add(Att)
     Next
     RebexMessage.Subject = Message.Subject
     RebexMessage.BodyHtml = Message.Body
     RebexMessage.Headers.Add("X-Unsent", "1")
     RebexMessage.Save(InternalFileName, MailFormat.OutlookMsg)
  End Sub

3 Answers

0 votes
by (72.7k points)
edited
 
Best answer

I post here the conclusion from our mail communication for other visitors:

There is a difference between using Outlook with Exchange server or with other servers.

Microsoft Exchange server requires user (EX record) in the Form field whereas MailMessage uses email address (SMTP record).

If you want to send the MSG from Outlook using MS Exchange you have to specify Exchange user for the specified SMTP address. Basically you need to do the opposite of ExToSmtp method specified in this post.

Please note that Exchange has “a lot of usernames”. E.g. when tested with my account I can specify mail.From = “Lukas Matyska”, “Lukas M”, “lukasm” or “lukas.matyska”; and everything works fine, however lukas.matyska@rebex.cz fails...

You probably have to set mail.From to “TKBUSR9901” or to “Beheer”.

Later we discovered that including both EX username and SMTP address in the From field works (when sending Exchange takes EX username and ignores SMTP address). So in my case I can do:

// EX user, SMTP address
mail.From = "Lukas Matyska, lukas.matyska@rebex.cz";

instead of (which is not working):

// SMTP address with Display name
mail.From = "Lukas Matyska <lukas.matyska@rebex.cz>";
0 votes
by (58.9k points)
edited

Hello,

please use Sender instead of From property when initializing Rebex MailMessage properties. This will make Outlook work as expected.

In your code you only have to change 1 line within If statement:

    If Not Message.[From] Is Nothing Then
        ' use Sender instead of From
        RebexMessage.Sender = Message.From.Address
    End If
by (250 points)
edited

Hi,

Unfortunately, that appears to do nothing at all. I don't get an email address pre-filled in the From-field when I use Sender instead of From.

0 votes
by (72.7k points)
edited

It may be caused by various things - version, service pack, domain politics, combination of Outlook and Exchange, etc.

I've tried:

  1. Outlook 2003, Professional, SP3, EN-US, out of domain - it doesn't perform address validation at all. I was able to send the mail with Sender and/or From specified to any value (even using non-existing domain).

  2. Outlook 2010, Professional Plus, CS-CZ, in domain - it performs address validation, but I was able to send the mail if the Sender was specified to my address and From was left empty.

Please try to specified both Sender and From. If it doesn't help do this:

  1. create .msg file using Rebex (specify From)
  2. open it with Outlook 2003, rewrite from address and save this message to a .msg
  3. send the mail, find it in Sent items and save this message to a .msg
  4. zip all three .msg files and send the zip file to support@rebex.net

I will try to find the cause of the problem by comparing those files.

by (250 points)
edited

Thank you, I have sent the requested files. I was unsure whether or not you wanted files for just the From address, or both filled in, so I supplied both.

...