Send email from mailbox in Python - python-3.x

currently I am using the win32com.client way of sending emails via Python 3, as I do not have access to SMTP. My code is below for reference:
def send_email(recipient, content, cc):
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipient
mail.Subject = content[0]
mail.HTMLBody = content[1]
mail.CC = cc
mail.Send()
My question is, is there a way to send an email using this method but send it 'from' another mailbox from within my outlook. For example, I have my email "name#domain.com" and a mailbox called "application#domain.com", which I have send as rights on. Is there a way to change it so that it'll send from the "application#domain.com" email? I haven't been able to find any documentation on this query.

managed to find the solution! If anybody else needs it, use the property:
newMail.SentOnBehalfOfName = 'SharedFolder'
Thanks to programmatically send outlook email from shared mailbox

Related

Mime_content in reply email (exchangelib, python)

First - I use the exchangelib package to connect to EWS exchange.
I will create a reply to the email as follows:
msg = acc.inbox.all().order_by('-datetime_received')[-1]
mgs.reply_all("Re: Subject", "body of email")
But the response created this way doesn't have the mime_content option, which I need to be able to save the email as .eml or .msg.
The msg variable has mime_content.
Is there a way to create an email reply with mime_content?
Thanks a lot!
reply_all() does not return anything. It's just a helper for sending a reply to the email it's called on.
If you want to access the Message item that the reply created, you need to search your "Sent" folder for the reply. That message has the mime_content field you're looking for.
If you call msg.create_reply_all(subject, body).send() instead, then you should get back the ID of the item stored in the "Sent" folder so you don't have to search for it.

Email from python sending email id with Comma in between the email address

I am sending email from python using gmail. Email is coming without any problem. But, the email id is showing with comma.
For example :
If to_email = 'ayan#zzzz.com'
In the recipient mailbox it is showing as : 'a,y,n,z,c,o,m'
Where as from email is absolutely fine.
Please let me know the solution

Node.js: AWS SES sendRawEmail: mails not getting sent to BCC addresses

I am sending a mail with attachments using mailcomposer and the sendRawEmail method of the AWS SDK. I am able to send the emails using the to and cc fields but when I add an address in bcc, the mail does not get delivered. There is no failure though. Is there any extra configuration not mentioned in the docs that I might be missing ?
I found the answer in one of the issues of mailcomposer. You need to add one extra config in the mail options.
var mail = mailcomposer(options);
mail.keepBcc = true;

How to get body of mail by message-ID or any header

I'm creating an email app. To save time, I just download subject and some header and saved them to database, not download body of mail.
And then, If user click on subject, I will download body of this mail.
I try to use Message-ID (because it's unique) to make it is an index. and Using this code to find this mail on server
SearchTerm term = new MessageIDTerm(ID);
message_s = folder.search(term);
But it just success on GMAIL, some other server, this code doesn't work correct.
I try to get All message-ID and compare it on client side, It toke a lot of time to find, user can't wait too long to get body of email.
Anyone has an idea to find and download body of email correctly by Message-ID or by any header ?

'Microsoft.SharePoint.MailMessage' is inaccessible due to its protection level

'Microsoft.SharePoint.MailMessage' is inaccessible due to its protection level
On this code:
MailMessage mail = new MailMessage();
mail.From = "myemail#xxxxx.edu";
mail.To = "myemail#xxxx.edu";
mail.Subject = "Testing Code";
mail.BodyText = what;
mail.Priority = MailPriority.High;
Smtp.Send(mail, "smtp.xxxxx.edu");
How can remidy this? changes to web.config? Any way to circumvent in code?
This error is saying that MailMessage does not have public constructor. Most likely, it is for internal SharePoint use only.
Actually, in most cases in SharePoint you need to use SPUtility.SendEmail method to send mail with SharePoint. It is very simple:
SPUtility.SendEmail(SPContext.Current.Web, false, false, "myemail#xxxxx.edu", "Testing Code", what);
See MSDN for details on this method:
http://msdn.microsoft.com/en-us/library/ms411989.aspx
If you need to send email under ordinary user accounts, you should use SPSecurity.RunWithElevatedPrivilegies method to provide elevated privilegies.
Only disadvantage is that SPUtility does not support attachments. If you need attach some files to your letter, please use System.Net.Mail.
I know a good post from Edwin Vriethoff, which provide detailed information about sending email with attachments, with default SharePoint SMTP settings (they are configured through Central Administration):
http://edwin.vriethoff.net/2007/10/02/how-to-send-an-e-mail-with-attachment-from-sharepoint/

Resources