YiiMail sending attachment - yii

In my Project i am using YiiMail extension to send mail to the users. in which i am attaching a file. but the problem is its not possible to send the mail using the attachment. my mail code is given below.
$this->email->setBody('<p>'.$email.'-'.$name.'-'.$details.'</p>', 'text/html');
$this->email->from = "test#test.com";
$this->email->setSubject('Direct Request');
$this->email->attach(CUploadedFile::getInstanceByName('fileupload'));
$this->email->setTo(array($emailId => 'test#test.com'));
with this code the mail is not sending and error message is showing.
Argument 1 passed to Swift_Mime_SimpleMessage::attach() must implement interface Swift_Mime_MimeEntity, instance of CUploadedFile given
what is reason this error is showing and any solution for this.
thanks in advance

You need to convert your file attachment to a SwiftMailer Swift_Mime_MimeEntity type. CUploadedFile::getInstanceByName('fileupload') returns a CUploadedFile class, which SwiftMailer does not know how to handle. More on Swift attachments here.
I have not tested this, but you will need to do something like this:
$uploadedFile = CUploadedFile::getInstanceByName('fileupload'); // get the CUploadedFile
$uploadedFileName = $uploadedFile->tempName; // will be something like 'myfile.jpg'
$swiftAttachment = Swift_Attachment::fromPath($uploadedFileName); // create a Swift Attachment
$this->email->attach($swiftAttachment); // now attach the correct type
Good luck!

Related

How to resend verification code while verifying/updating attribute in aws-amplify/ aws-cognito?

How to resend verification code while verifying/updating email/phone attribute in aws-amplify/ aws-cognito, I'm using this code, to verify email/phone:
const responce = await Auth.verifyCurrentUserAttributeSubmit("email", confirmationCode)
Is there a possibility to resend the code?
I am sure you already tried this but would calling this method again, asking for a new code, not work for you:
https://aws-amplify.github.io/amplify-js/api/classes/authclass.html#verifyuserattribute

Saving msg file attachment using EWS API

Hope someone can help. I am implementing a feature where you can choose an email attachment and save it within a database. The feature works fine with PDF etc but when it comes to MSG files it creates a ItemAttachment not a Fileattachment and does not give me the ability to get the content or content type.
I have found this post about saving messages as .eml but ideally as the email had an .msg attached this is what should be saved in the system. I have done some extensive searching but have come to a dead end.
I am using asp.net so answers in VB.net would be appreciated.
Thanks
EDIT: Sorry, I did not see you were using VB, for now I won't delete my post since it can still give you an idea of how to handle this, I know that when I struggled with this, my thought of process was just incorrect and the actual syntax was not a challenge.
I am fairly new to this website so excuse me if I am not formatting my answer correctly.
Assuming you already established your exchange connection, created a new ItemView, and retrieved all emails from your inbox, we will start off by creating a secondary list of emails, but we are only going to list the emails that contain an Item Attachment.
List<EmailMessage> emailsWithItemAttachment =
emails.Where(e => e.HasAttachments && e.Attachments[0] is ItemAttachment).ToList();
Now, we can loop only the emails with Item attachment(s)
foreach (EmailMessage emailMessage in emailsWithItemAttachment)
{
//Loads all emails with Item attachments as an item attachment
foreach (Attachment attachment in emailMessage.Attachments)
{
attachment.Load();
ItemAttachment itemAttachment = attachment as ItemAttachment;
if (itemAttachment == null) continue;
ItemAttachment itemattachment = attachment as ItemAttachment;
itemattachment.Load(new PropertySet(ItemSchema.Attachments));
//Loads the scanned Attachment as an Item Attachment
foreach (Attachment scannedAttachment in itemattachment.Item.Attachments)
{
scannedAttachment.Load();
//Loads all Item Attachments as File Attachments
FileAttachment fileAttachment = scannedAttachment as FileAttachment;
if (fileAttachment != null)
{
//All Done! Your attachment will be "fileAttachment", from here you can do whatever you want
}
}
}
}
I really hope this helps you, and again if anything is wrong about my answer please do not hesitate to edit and/or contact me!
When querying an ItemAttachment, add the MimeContentPropertyDefinition (sorry, don't remember the exact names and classes). Then your ItemAttachment will have that MimeContent property set - that's a text (MIME) that you can save to a file in UTF-8 encoding with .EML extension. MIME is a standard, so that .EML file can be opened by any mail client app.

Interfax developer account configuration for multiple recipients

I want to configure an interfax account for sending and receiving faxes.
Can anyone tell me how to send/receive a test fax?
I know about the .sendFax() and .GetList() methods, but how do I send fax to myself (in test account)?
I followed the article,
Receive incoming faxes via callback to a web application
it works fine. But it only gives you intimation that you have received fax.
Edit:
You can set feedback url and use the parameter which they asked. When interfax will receive fax for you, it will send it to your feedback url and it will go directly to your database (If you set this in page load event).
You can use following code
MessageItem[] faxList = null;
Inbound inbound = new Inbound();
ListType messageListType = ListType.NewMessages;
int interFaxResult = inbound.GetList(AppConfig.InterfaxUsername, AppConfig.InterfaxPassword, messageListType, AppConfig.InterfaxMaxitems, ref faxList);
if (interFaxResult == 0)
{
// Save faxes in DB
}

Testing WCF with SoapUI

I need your help on one practical issue. I have created a WCF service with basic binding with two operation contact.
1- void StartRegistration - Anonymous member can fill the basic registration form and press submit. All the information will be stored into the database and one link with some random token will be send to user's email address.
2 - void CompleteRegistration - This method validates the token sent into the email address and if token is valid, user account will be activated.
Now I have issue here. Using SoapUI I can call StartRegistration method. Email is sent to destination but I want to pass the token to CompleteRegistration method.
Since it is a WCF service so can not do dependency injection to pass the SoapUI tests :).
Please help.
If I understand your question correctly, you have two WCF methods, one for creating a token and another for confirming it.
What I would do in this case is have the first method, StartRegistration, return the token. Then you could use that token to pass into the CompleteRegistration method quite easily in Soap UI.
Another, quite messy solution, would be to have a groovy script test step in Soap UI that actually connected to the mail account, read the link and parsed the contents.
Edited:
Here is part of the script you'll need. Place it in a groovy step, that will then return the token from your mail.
Note: This code assumes that mail is plain text, not multipart. It also assumes that the mail box only has a single mail. The API for JavaMail is pretty extensive, so if you want to do any magic with it, Google is your friend :) At least, this is somewhere to start.
import javax.mail.*;
import javax.mail.internet.*;
// setup connection
Properties props = new Properties();
def host = "pop3.live.com";
def username = "mymailadress#live.com";
def password = "myPassword";
def provider = "pop3s";
// Connect to the POP3 server
Session session = Session.getDefaultInstance props, null
Store store = session.getStore provider
Folder inbox = null
String content
try
{
store.connect host, username, password
// Open the folder
inbox = store.getFolder 'INBOX'
if (!inbox) {
println 'No INBOX'
System.exit 1
}
inbox.open(Folder.READ_ONLY)
Message[] messages = inbox.getMessages()
content = messages[0].getContent()
//Do some parsing of the content here, to find your token.
//Place the result in content
}
finally
{
inbox.close false
store.close()
}
return content; //return the parsed token

How to check email using a vb.net application

I am looking for a vb.net code for receiving e-mails without using any 3rd party libraries. I want to check Unread messages, Inbox and Sent messages. A Working sample is appreciated.
What is the default port for SMTP , is it port 25 (is it the same for all SMTP mail servers?). Which is more flexible in my case POP3 or IMAP ?
Edit:
Someone please give me a sample working code for receiving mail using lumisoft (pop) in vb.net
From lumisoft Help.
/*
To make this code to work, you need to import following namespaces:
using LumiSoft.Net.Mime;
using LumiSoft.Net.POP3.Client;
*/
using(POP3_Client c = new POP3_Client()){
c.Connect("ivx",WellKnownPorts.POP3);
c.Authenticate("test","test",true);
// Get first message if there is any
if(c.Messages.Count > 0){
// Do your suff
// Parse message
Mime m = Mime.Parse(c.Messages[0].MessageToByte());
string from = m.MainEntity.From;
string subject = m.MainEntity.Subject;
// ...
}
}
Pop is more supported and most servers have it on if you want to implement your own pop service a good place to start is the rfc.