Hi,
I have develop batch job to send emails, using the SMTP server. I have set the email parameter, for testing and its working fine for me. But when try to go live, I have notice there was already email parameters are configure with some abc@test1.com. When I tried to send email with from email address test2.com, I have got authentication error. As the given authentication given for test1.com. Now I need to send the email using other server like xyz@test2.com.
If I replace the sender with mine one. Then the other department will complain their email are not going to deliver. I think I need to configure email server at run time, or what may the possibility.
Please help, Here is the code which I am using to send email.
public boolean sendEmail(Email emailTo, str emailSub, str emailBody, str CC1, str CC2, str CC3)
{
SysMailerMessageBuilder messageBuilder = new SysMailerMessageBuilder();
SysEmailParameters parameters = SysEmailParameters::find();
Email fromEmail;
System.ArgumentException ex;
try
{
fromEmail = "No-reply";
messageBuilder.setBody(emailBody,true);
messageBuilder.setSubject(emailSub);
//messageBuilder.addTo("myletter@company1.com");
messageBuilder.addTo(emailTo);
if (CC1!="")
messageBuilder.addCc(CC1);
if (CC2!="")
messageBuilder.addCc(CC2);
if (CC3!="")
messageBuilder.addCc(CC3);
messageBuilder.addCc("xyz@company1.com");
// Note: not calling setFrom() defaults to the current user for SMTP client, whereas
// when sent to Outlook any setFrom() value will be ignored since profiles on the client are used
messageBuilder.setFrom(fromEmail);
// Open the generated email in the configured client
// Sends a message interactively, allowing the user to view and modify the message before
SysMailerFactory::sendNonInteractive(messageBuilder.getMessage());
// Try using sendNonInteractive method too
}
catch (ex)
{
throw error(ex.Message);
}
return true;
}
Email setting parameters
