Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Here this code is sending two emails to outlook. one with newMessage and other with MailManager. Could you please help to make it as one email and send both the contents on one email.

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
var assembly = Assembly.GetExecutingAssembly();
byte[] bytes = xyz.Properties.Resources.Template;


TinyUser tu = new TinyUser("r7929");
EmailMessage newMessage = new EmailMessage(service);



newMessage.SetExtendedProperty(binaryProperties, bytes);



tu.EMail = newMessage.ToRecipients.Add("niad@outlook.com").ToString();

Absence ab = ServiceLookup.APServerProxy.GetAbsence(842);
Absences abs = new Absences();
abs.Add(ab);

UserAbsences ua = new UserAbsences(tu, abs);
UsersAbsences usa = new UsersAbsences();
usa.Add(ua);

Console.WriteLine("Absence of (842");
AccreditorUsersAbsences aua = new AccreditorUsersAbsences(tu, usa);

TinyUser tua = new TinyUser("r7929");
tua.EMail = newMessage.ToRecipients.Add("niad@outlook.com").ToString();
aua.Accreditor = tua;

MailManager.Instance.SendMailToAccreditor(aua);

newMessage.Subject = "Request for vacation";
newMessage.Body = new MessageBody("Email Body");
newMessage.Send();
Posted
Updated 5-Aug-14 1:49am
v3
Comments
[no name] 5-Aug-14 9:40am    
Why don't you simply send the same message to both recipients?
Lassi91 5-Aug-14 10:01am    
yea im sending in the same way, it is creating two emails. but i want this in a single email.
[no name] 5-Aug-14 10:21am    
No it is creating two emails because that is the way you coded it.
Lassi91 5-Aug-14 10:28am    
could you please let me know how can combine them. because one email is created by microsoft exchange service and other by dotnetopen email. do u have a process to combine these two emails?

1 solution

Just remove this line:
MailManager.Instance.SendMailToAccreditor(aua);


You have already added both recipients to newMessage. I don't totally understand what you are doing with your classes, but this will reduce the code to only send one message via Microsoft exchange. I am guessing that MailManager is a internal class that you built and the SendMailToAccreditor method creates a message fully populated email when called with a parameter of type AccreditorUsersAbsences.

I have no idea what you are wanting but if you just want one email to go out remove the line above if you want the email that is sent from MailManager to go out (email body wise) then you will need to modify that class and remove the newMessage.

I hope that helps. Without knowing exactly what you want and Combining them into one email is not a good answer because you are sending 2 messages one is being generated in this code and one is being generated in MailManager so more info is needed before I can give anymore help.

Damien
 
Share this answer
 
Comments
Lassi91 8-Aug-14 5:05am    
hi,
Please let me know how can provide you with details.

To be more clear MailManager is sending one mail(dotnet mail) and exchange service is sending other mail. These two are sending two differnet mails. I want to combine both of them.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900