PHP SwiftMailer from string to Message object - swiftmailer

As we know we can get email string from Swift Message object:
$message = new Swift_Message();
$message->setSubject("hi");
$message->attach(Swift_Attachment::fromPath('a.txt'));
$message->toString();
But can I parse mail string into Message object ?
Great thanks!

I think php-mime-mail-parser can solve your problem:
A fully tested email parser for PHP 7.1+ (mailparse extension wrapper).
It's the most effective php email parser around in terms of performance, foreign character encoding, attachment handling, and ease of use. Internet Message Format RFC 822, 2822, 5322.
https://github.com/php-mime-mail-parser/php-mime-mail-parser

IT's not possible with Swift mail

Related

how to send email attachments using power automate to webapi

I am new to power automate. I need to read my email attachments and send each attachment to webapi as base64. I used below expression to convert email attachment to base64. but flow shows error as "Correct to include a valid reference to 'Get_Attachment_(V3)' for the input parameter(s) of action 'HTTP'.
what should be correct expression to convert attachment to base64.
expression: base64(body('Get_Attachment_(V3)')?['contentBytes'])
error:
A couple of things.
Firstly, in your JSON body, you just need to put quotes around the value of the content property.
Secondly, make sure you have a Get Attachment (V#) step prior to the HTTP action.
This step actually retrieves the contents of the attachment.

How to read gmail inbox messages and extract the data from the email in a word/excel folder using UiPath?

I'm using gmail account to extract the data, from the body of the mail and I want to store that data in a word/excel folder.
Can someone explain the process to achieve this?
The email body would be like this:
Hello!
First name
John
Last name
Doe
Email
sample#gmail.com
Message
Text
You can read the email using the Get IMAP Mail Message activity and get the Body of Email in a Text then you can use the String manipulation/regex to find the required text and then store it in Excel/Word.
You may need to keep the following things in mind.
You will need to create an App Password by going to your Google Account Settings (https://myaccount.google.com/apppasswords) and use that Password in the Get Mail Message Activity.
To Get the Email Body the EmailMessage.Body property will not work instead you will need to use the EmailMessage.Headers("PlainText") Here EmailMessage is the Each Email Message from the list of Message. Here is the screenshot.
Above If condition is used to check if the Subject of Email which we want to read.
Once you get the Email Body in a String Variable you can use either String Manipulation or Regex to extract the required data from the body of the email and write to the excel or word.
Hope this helps.

How to turn message into a string

Can I turn a message into a string? I've tried just using the variable message to do that but it doesn't seem to work. I've tried...
print(message)
and all it told me was the message id and sender, and not the raw text or content.
You're looking for message.content. Just printing out message will give you the attributes and such values that you'll have access to.
If you're planning on seeing the "clean" version of the content, if it has mentions of users or channels in it, you can instead use the message.clean_content attribute.
See the references for more info on the attributes of the Message object.
References:
Message.content
Message.clean_content

Blank Email issue in magento for new order

In my magento website As soon as someone places order , an email is sent to his/her emailid. In the email the subject is correct but there is no body in the message, i mean the message comes blank.
i added new template from Transactional Emails section and associated this template with the Order from configuration->sales emails. but still my subject of the template reaches to mails but not the body. the message body remains empty always.
please help me solve this issue
thanks in advance
Looks like there is some error during rendering the email template. Try to replace your email template body with something simple.
Magento doesn't trigger any error when the template is not returned/processed properly.
The trace is:
Mage/Sales/Model/Order.php - sendNewOrderEmail()
Mage/Core/Model/Email/Template/Mailer.php - send()
Mage/Core/Model/Template.php - send()
Some things to check first - is the email valid for send, see the conditions below:
public function isValidForSend()
{
return !Mage::getStoreConfigFlag('system/smtp/disable')
&& $this->getSenderName()
&& $this->getSenderEmail()
&& $this->getTemplateSubject();
}
Another thing to look for:
If you copy-pasted some of the email content you might have some characters in the email that are not ASCII. This causes a crash when the template is parsed and there is no error logged/displayed.
This can be checked by using the standard Magento email template and if that works and your custom template doesn't.
I found that the cause of the error was the vars:
{{config path='trans_email/ident_support/email'}}
{{config path='general/store_information/phone'}}
If these are deleted/substituted, then the emails are being sent without errors.

Mail gem - how to clean up the body string

I'm trying to read an email using ruby mail gem.
But mail.body.decoded returns me not just the body message. How can I clean up this body message and remove unwanted text like:
-20cf30433c9a437cc304939017ef\nContent-Type: text/plain; charset=ISO-8859-1\nContent-
message = $stdin.read
mail = Mail.read_from_string(message)
puts mail.body.decoded
--20cf30433c9a437cc304939017ef\nContent-Type: text/plain; charset=ISO-8859-1\nContent-Transfer-Encoding: quoted-printable\n\n REAL BODY TEXT \\n\n--20cf30433c9a437cc304939017ef\nContent-Type: text/html; charset=ISO-8859-1\nContent-Transfer-Encoding: quoted-printable\n\n<br clear=3D\"all\">--20cf30433c9a437cc304939017ef--
How can I clean up this email body mail message extracting only the REAL BODY TEXT , without ANY header ?
I'm creating a simple Ticket System based in Ruby on Rails, and a ticket is created when an email is received by ticket#mydomain.com. But when the message is in HTML format the BODY TEXT is surrounded by HEADERs text.
If you have a properly formatted email, you can use Mail helper methods:
mail = Mail.new(email_string)
mail.text_part # finds the first text/plain part
mail.html_part # finds the first text/html part
This doesn't always work if you have e.g. single part messages (text only) or receive email from the internet at large since you can't rely on formatting from every client out there. Believe me, I've learned the hard way.
looks like you've got a multipart email, so you can use
mail.parts[0].body.decoded
These will probably come in handy too:
mail.multipart?
mail.parts.length
The gem documentation at github is pretty decent
With the mail gem, you can do:
text = mail.multipart? ? mail.text_part.decoded : mail.body.decoded`
Add the mail gem and just use email body format with mail.parts[1].body.decoded.

Resources