Messages.Add(), manually add a message ?

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
mekola
New user
New user
Posts: 7
Joined: 2020-05-05 13:36

Messages.Add(), manually add a message ?

Post by mekola » 2020-05-19 00:38

Hi, i am trying to add a new message into "Sent" imapfolder manually.

When the message is sent, i want to save the message in the "Sent" box.

I can add the message to the sent box, but the message is coming empty ( only date coming that i can see )

I couldn't save message From, Fromaddress or Body etc.

this is my simple code:

Code: Select all

// This for send message

            string subject = model.subject;
            string recipient = model.recipient;
            string body = model.body;
            hMailServer.Message message = new hMailServer.Message();
            message.From = "from";
            message.FromAddress = "fromaddress";
            message.Subject = subject;
            message.AddRecipient(recipient, recipient);
            message.Body = body;
            
// This for Sent Box

            hMailServer.ApplicationClass application = new hMailServer.ApplicationClass();
            application.Authenticate("Administrator", "password");
            hMailServer.Domain domain = application.Domains.ItemByName["domain.com"];
            hMailServer.Accounts accounts = domain.Accounts;
            hMailServer.Account mailbox = accounts.ItemByAddress["someone@domain.com"];
            hMailServer.IMAPFolders imapFolders = mailbox.IMAPFolders;
            hMailServer.IMAPFolder imapfolder = imapFolders.ItemByName["Sent"];
            hMailServer.Messages messages = imapfolder.Messages;
            
// This for Adding message into "Sent" box

            message = messages.Add();
            message.Save();
I tried in many different syntaxes, these codes may sound bad to you, sorry

If these codes are incorrect, can you show me a way , I can manually add them with the Messages.Add () command

is it possible manually? Messages.Add () with message content

Thank you.

User avatar
mattg
Moderator
Moderator
Posts: 20788
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Messages.Add(), manually add a message ?

Post by mattg » 2020-05-19 01:25

I have tried this with varying levels of success


I suspect that I'm closer as you overwrite 'message'

oApp.Domains.ItemByName(oDomain).Accounts.ItemByAddress(oMessage.FromAddress).IMAPFolders.ItemByName(SentFolderName).Messages.Add (oMessage)
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

mekola
New user
New user
Posts: 7
Joined: 2020-05-05 13:36

Re: Messages.Add(), manually add a message ?

Post by mekola » 2020-05-19 01:51

mattg wrote:
2020-05-19 01:25
I have tried this with varying levels of success


I suspect that I'm closer as you overwrite 'message'

oApp.Domains.ItemByName(oDomain).Accounts.ItemByAddress(oMessage.FromAddress).IMAPFolders.ItemByName(SentFolderName).Messages.Add (oMessage)
Thank you for your answer.

When i tried your code as . . . Messages.Add(oMessage)

it says, too many arguments. It doesn't want any value into parenthesis.

as I understand from your answer, there is no way for now adding message manually :(

am i right?

Post Reply