Email clients for Dynamics AX - smtpclient

I am wondering how the process of sending email is working between Dynamics Ax client and Email client that is set for the server as default email client.
First of all can Dynamics Ax use alternative email clients (not outlook) for sending emails and second of all is Dynamics Ax sending whole configuration to the client, or client has to be configured by itself.
Right now I am experiencing unknown error while trying to send email using Windows Live Mail.

Dynamics AX uses MAPI for client mail.
You can use the SysINetMail::sendEMail method to send a simple mail using this.
If you mail in batch another option is to use SMTP mail using SysEmailTable::sendMail.
This requires the use of mail templates.

I know this is an old question but if someone else needs it...
I am using this on a Dynamics AX 2009 and it works like a charm :)
server static boolean sendEmail(EmplId _fromEmplId, EmplId _toEmplId, str _subject, str message, EmailPriority _priority = EmailPriority::Normal)
{
boolean ok = true;
SysEmailBatch emailBatch;
EmplTable fromEmplTable;
EmplTable toEmplTable;
Email fromEmail;
Email toEmail;
;
changecompany( -- TO YOUR MASTER COMPANY --)
{
fromEmplTable = EmplTable::find(_fromEmplId);
toEmplTable = EmplTable::find(_toEmplId);
fromEmail = fromEmplTable.email();
toEmail = toEmplTable.email();
if (! fromEmail)
{
ok = checkFailed(strfmt("no email set up for %1", _fromEmplId));
}
if (! toEmail)
{
ok = checkFailed(strfmt("no email set up for %1", _toEmplId));
}
if (ok)
{
emailBatch = SysEmailBatch::construct();
emailBatch.parmSendername(fromEmplTable.name());
emailBatch.parmSenderAddr(fromEmplTable.email());
emailBatch.parmEmailAddr(toEmplTable.email());
emailBatch.parmPriority(_priority);
emailBatch.parmSubject(_subject);
emailBatch.parmMessageBody(_message);
emailBatch.run();
}
}
return ok;
}

Using SysOutgoingEmailTable and SysOutgoingEmailData you can send email to recipient of any domain and attach files too.
you have following fields:
outgoingEmailTable.EmailItemId
outgoingEmailTable.IsSystemEmail
outgoingEmailTable.Sender
outgoingEmailTable.SenderName
outgoingEmailTable.Recipient
outgoingEmailTable.Subject
outgoingEmailTable.Priority
outgoingEmailTable.WithRetries
outgoingEmailTable.RetryNum
outgoingEmailTable.UserId
outgoingEmailTable.Status
outgoingEmailTable.Message
outgoingEmailTable.TemplateId
outgoingEmailTable.LatestStatusChangeDateTime
outgoingEmailData.EmailItemId
outgoingEmailData.FileName
outgoingEmailData.EmailDataType
outgoingEmailData.FileExtension
insert respective email detail in these tables and you are good to go. Further if it gives permission error do add permission set with
CodeAccessPermission::assertMultiple .

Related

Mail code works in localhost but not on the URL website afterwards

I made a web application on visual studio 2017 for ASP.NET core. It has a contact option where users send me an email. It works perfectly in localhost as I receive the feedback. When I build/release using Azure DevOps onto azure app services in the portal my website at its URL loses the functionality of the email option. I wrote the email code using MailKit, if you guys have a better option that works let me know! Thank you.
var message = new MimeMessage();
message.From.Add(new MailboxAddress(inputEmail));
message.To.Add(new MailboxAddress("myemail"));
message.Subject = "Message from: " + inputName;
message.Body = new TextPart("plain")
{
Text = inputMessage
};
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587, false);
client.Authenticate("email", "password");
client.Send(message);
client.Disconnect(true);
};
return RedirectToAction("Index");
mywebsite.azurewebsites.net is currently unable to handle this request.
The problem is that you are using gmail. GMail only allows you to authenticate using SMTP/IMAP/POP3 after you've authenticated via the web from a particular device.

Unable to relay recipient in non-accepted domain

All emails with the domain #mycompany.com are sent successfully. But, if MantisBT wants to send an email to anyone else, for example #othercontractor.com, or #gmail.com, etc , the email is not sent.
In addition, a collateral damage of this problematic email is that it will get stuck in "MySqlDatabase/mantis_email_table" and all the emails after this problematic email in that table won't be sent. So, to fix it, I have to manually delete that entry in the table. It is not very convenient when I want to add contractor who has his own email domain in our bug tracker.
This the email configuration in: /path_to_mantis_bt/config/config_inc.php
// Email Configuration
$g_email_send_using_cronjob = ON;
$g_allow_signup = ON; //allows the users to sign up for a new account
$g_enable_email_notification = ON; //enables the email messages
$g_phpMailer_method = PHPMAILER_METHOD_SMTP;
$g_smtp_host = 'edge.mycompany.com';
$g_smtp_connection_mode = '';
$g_smtp_port = 25;
$g_administrator_email = 'myname#mycompany.com';
$g_from_email = 'myname#mycompany.com';
$g_return_path_email = 'myname#mycompany.com';
$g_from_name = 'Mantis Bug Tracker';
I should mention that we are hosting MantisBT on our own server Microsoft Server 2012 R2 and WAMP(latest version).
The error: 2018-01-08 10:24 PST MAIL email_api.php:1379 email_send() ERROR: Message could not be sent - SMTP Error: The following recipients failed: xxx#gmail.com: 5.7.54 SMTP; Unable to relay recipient in non-accepted domain
It's working now, but I used sendmail instead of using the WAMP/SMTP.
To install SENDMAIL on WAMP, I followed these instructions
This the email configuration in: /path_to_mantis_bt/config/config_inc.php
$g_allow_signup = ON; //allows the users to sign up for a new account
$g_enable_email_notification = ON; //enables the email messages
$g_phpMailer_method = PHPMAILER_METHOD_SENDMAIL; //If not using sendmail, use: PHPMAILER_METHOD_SMTP;
$g_smtp_host = 'edge.mycompany.com';
$g_smtp_connection_mode = 'tls';
$g_smtp_port = 587;
$g_smtp_username = 'xxx'; // my username for email myname#mycompany.com
$g_smtp_password = 'xxx'; // my password for email myname#mycompany.com
$g_administrator_email = 'myname#mycompany.com';
$g_webmaster_email = 'myname#mycompany.com';
$g_from_email = 'myname#mycompany.com';
$g_return_path_email = 'myname#mycompany.com';
$g_from_name = 'Mantis Bug Tracker';
// Log configuration
$g_log_level = LOG_EMAIL | LOG_EMAIL_RECIPIENT | LOG_FILTERING | LOG_AJAX;
$g_log_destination = 'file:/wamp64/logs/mantis.log';
?>
IF you follow the link above, you will know how to update php.ini and sendmail.ini . Update these 2 files with the information in config_inc.php.
I had the same issue. In my case, we were sending out emails from an application and there was a user bcced (hardcoded in the code) which was not in the domain and hence it failed
I had same issue once I changed to #newdomain.com.
In my case I found suggestion on the web to clear cache of my browser. I did and all start working.
Basically, you need to reload all config files from scratch with new globals...
At least it worked for me.
Cheers.

Which do i need Sendgrid or Mailkit - to send emails from azure webjob

Can i use Mailkit to send emails from an azure webjob using an organizational smtp server? Or do i need to use Sendgrid?
Mine is a .net core 1.1 console application which i then hosted as azure webjob.
For some reason, I am not able to get my webjob working with Mailkit using an organizational Smtp server. The job runs successfully, does not log any errors. BUT not able to send mails out..
here is my code that uses mailkit
using (var client = new SmtpClient())
{
try {
// For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
Logger.LogInformation("Ready to connect to smtp server");
client.Connect(Constants.SMTP_HOST, 25, false);
Logger.LogInformation("connected to smtp server");
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
Logger.LogInformation("Ready to send email");
client.Send(message);
}
catch (Exception ex) {
Logger.LogError("An error occurred");
Logger.LogError(ex.StackTrace);
}
finally {
client.Disconnect(true);
}
}
Can i use Mailkit to send emails from an azure webjob using an organizational smtp server?
If you use the organizational smtp server, then should make sure that your email server policy allowed to that.
I test Mailkit in the Azure WebJob with google email. It works correctly on my side. Before that I turn Allow less secure apps: ON for my gmail account
The following is the demo code.
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Tom Gmail", "xx#gmail.com"));
message.To.Add(new MailboxAddress("Tom Hotmail", "xxx#hotmail.com"));
message.Subject = "I am a mail subject";
message.Body = new TextPart("plain")
{
Text = "I am a mail body."
};
using (var client = new SmtpClient())
{
client.Connect("smtp.gmail.com", 587);
// Note: since we don't have an OAuth2 token, disable
// the XOAUTH2 authentication mechanism.
client.AuthenticationMechanisms.Remove("XOAUTH2");
// Note: only needed if the SMTP server requires authentication
client.Authenticate("sunguiguan#gmail.com", "#WSX3edc");
client.Send(message);
client.Disconnect(true);
}
Console.WriteLine("send mail successful");
Console.Read();
Or do i need to use Sendgrid?
On my opinon, SendGrid also is a good choice, we also could use the free price tier on the Azure. I also test it on myside. it also works correctly. We also could get more detail info from azure official document.
var apiKey ="ApiKey";//System.Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage()
{
From = new EmailAddress("xxx#hotmail.com", "Send Grid"),
Subject = "Hello World from the SendGrid CSharp SDK!",
PlainTextContent = "Hello, Email!",
HtmlContent = "<strong>Hello, Email!</strong>"
};
msg.AddTo(new EmailAddress("xxxx#gmail.com", "Test User"));
client.SendEmailAsync(msg).Wait();
}

Issues sending mail from SMTP Server

I am a PHP Developer trying to learn ColdFusion and facing a simple but confusing problem.
I am sending email using the cfmail tag as follows:
<cfmail from = "abc#domain.com"
to = "sushilk#domain.com"
subject = "Testing mail"
server = "192.---.--.--"
password = "----"
port = "--"
username = "abc#domain.com">
It works great when from="abc#domain.com" and username="abc#domain.com", both have the same values. But if I use from="abc11#domain.com" the mail send fails and gets stored in CF Admin. Do I have to use the same from address as to SMTP username?
I'd bet it's a server configuration that rejecting you and not a Coldfusion error.
You can test by using TELNET to the SMTP host - http://technet.microsoft.com/en-us/library/aa995718(v=exchg.65).aspx

Mailing Through Exchange webservice (VB.NET)

Anyone here who has experience with using Exchange webservice.
I am trying to send an e-mail to myself using the webservice. This e-mail has another address as Sender, but it keeps taking my recipients e-mail address as Sender instead :s
This is my code:
Dim Message As MessageType = New MessageType()
Message.Subject = txt
Message.Body = New BodyType()
Message.Body.Value = ActiesOverzicht
Message.Sender = New SingleRecipientType
Message.Sender.Item = New EmailAddressType
Message.Sender.Item.EmailAddress = SenderEmail
Message.ToRecipients = New EmailAddressType(0) {}
Message.ToRecipients(0) = New EmailAddressType()
Message.ToRecipients(0).EmailAddress = RecipientsEmail
Message.Sensitivity = SensitivityChoicesType.Normal
this message goes into a list and is send with the following Code:
Public Sub SendMailToOperator(messageList As List(Of MessageType), esb As ExchangeServiceBinding)
' Create the CreateItem request.
Dim createEmailRequest As New CreateItemType()
' Specifiy how the e-mail will be handled.
createEmailRequest.MessageDisposition = MessageDispositionType.SendOnly
createEmailRequest.MessageDispositionSpecified = True
' Create the array of items.
createEmailRequest.Items = New NonEmptyArrayOfAllItemsType()
' Add the message to the array of items to be created.
createEmailRequest.Items.Items = messageList.ToArray()
'createEmailRequest.Items.Items(0) = Message
' Send a CreateItem request and get the CreateItem
' response.
Dim createItemResponse As CreateItemResponseType = esb.CreateItem(createEmailRequest)
End Sub
Does anyone have any Idea on how to solve this problem? Or what causes it?
AFAIK Exchange will normally always set the sender to the identity of the person logged in.
There are several ways around this, the easiest one being not using Exchange. Just send mail trough 'normal' SMTP.
If you have to use Exchange you should log in as the sender you're trying to use, or set up the permissions for the account you are trying to use as sender. The sender you're using should allow the account you use to login to send mail on it's behalf. The permissions can be changed through outlook.
There might also be a way to relax this restriction on the Exchange server, but I'm not an Exchange admin so I don't know how.