Our application uses javax.mail.MimeMessage, we are written this code
Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress("mail#xyz.com", "XYZ"));
From section changing work in gmail and yahoo but not working outlook,
can any tell reason for this.
You need to add msg.setSender(new InternetAddress(...));
Related
I am creating a contact form and was wondering if it is possible to show the user's email in the "from "field in a contact email box. I am using java mail api.
Now it looks like this
can I show users' emails instead of grazerteamroma#gmail.com?
It seems like a can`t get access to a user's to account to send the mail from their account, am I right?
Not possible to set the sender address without the email server/provider.
Try replyTo Field in your code.
you can try replyTo of MimeMessage class.
Here is the spring version MimeMessageHelper class, you can set it using MimeMessage also.
public void sendEmail(Mail mail)
{
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage, true);
mimeMessageHelper.setSubject(mail.getMailSubject());
mimeMessageHelper.setFrom(new InternetAddress(mail.getMailFrom()));
mimeMessageHelper.setTo(mail.getMailTo());
mimeMessageHelper.setText(mail.getMailContent());
mimeMessageHelper.setReplyTo(new InternetAddress("anupamXXXX#gmail.com"));
javaMailSender.send(mimeMessageHelper.getMimeMessage());
}
catch (MessagingException e) {
e.printStackTrace();
}
}
Using above code receiver will receive with replyto address on which he directly reply.
Java Mail is an API to talk to the backend (Mail User Agent to Mail Transport Agent communication). It is not related to presenting the mails to users at all.
So of course it is possible to users' email on the screen, be it the sender, the recipient or else. But this is a UI rendering issue, not Java Mail.
In other words: You are barking up the wrong tree.
But since you are asking:
Send email - here are examples
Receive email - here are examples
In case your question is just about how Google Mail can print the name of the recipient independently of the email address, it probably parses this (recipient/originator) string:
Alfred Neuman <Neuman#BBN-TENEXA>
See the specification for email messages: https://www.w3.org/Protocols/rfc822/#z10
I am working on sending emails through ews.
In some scenarios, users wants to be able to get an email (parentEmail) with another email (emailToAttach) attached. This emailToAttach is retrieved from the sent folder and then attached to the parentEmail.
However, I am getting a stackoverflow error when I am trying to do the following at setSubject:
EmailMessage parentEmailMessage = new EmailMessage(exchangeService)
ItemAttachment attachment = parentEmailMessage.attachments.
<EmailMessage>addItemAttachment(Item)
attachment.setName(emailToAttach.subject)
attachment.item.setSubject(emailToAttach.subject)
attachment.item.setMimeContent(emailToAttach.mimeContent)
Can anyone help figure out why is the stack over flow error produced?
I have this really weird problem and I'm not able to find a solution... I hope you can help me...
I'm working in Google App Engine to build my App (lets call it "MyApp"), to test, I have a cloned app renamed as "sandbox-MyApp".
I need to allow my users send a mail with some data, so I have a form where they can fill some information that will be added to the message.
I've working with this scenario a long time ago, but now I'm having issues, because, for some reason, my out-coming mails are not being received by the recipients...
It's a really weird thing about this, because, I can send one or two mails without problem, but after that, they suddenly stop, and after some code-changes, they work again.
I'm using Java.Mail to do the work,
I'm trying to send a simple HTML,
My "from" address is something like "userName#sandbox-myApp.appspotmail.com"
My Subject its something like: "Hello userName! There is some important message for you"
The message it's really simple, includes an image logo (served by an https://sandbox-myApp.appspot.com/img/logo.png), an invitation text and a single link to my app URL... (https://sandbox-myApp.appspot.com/)
My code it's real simple, based on the Google Documentation.
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(senderAddress, MimeUtility.encodeText(senderLabel, "UTF-8", "B"), "UTF-8"));
msg.addRecipient(javax.mail.internet.MimeMessage.RecipientType.TO, new InternetAddress(receiverAddress, receiverLabel, "UTF-8"));
if(responseAddress != null && !responseAddress.trim().isEmpty()){
msg.setReplyTo(new Address[] {
new InternetAddress(responseAddress, MimeUtility.encodeText(senderLabel, "UTF-8", "B"))
});
}
msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", "B"), "UTF-8");
msg.setContent(msgBody, "text/html;charset=UTF-8");
Transport.send(msg);
I've tried changing "from" to something like "app_admin#mydomain.com" and it works for a while, but after some mails (about 5 or 6), stop working too.
Most shocking thing: There aren't any error message on logs... The Cuota Viewer counts every sent mail (so I suppose it must being blocked somewhere else),
I've modiffied the message to omit any URL on the body and It works better, but I need to include it!.
Problem is tracked on https://code.google.com/p/googleappengine/issues/detail?id=12786
Workaround which worked for my application is to not use appspot.com domain.
Register custom domain for the application and then mails to the application using the custom domain work.
I am sending a mail in GWT using Google Oauth Authentication and token.
My Project use Google OAuthAuthentication.
The mail is send successfully . I just want to automatically include signature like we do in our mails while sending the mail.
I am able to send mail :
SMTPTransport transport = connectToSmtp(from, token);
Message msg = new MimeMessage(session);
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(toMail));
msg.addRecipients(Message.RecipientType.CC, InternetAddress.parse(ccMail));
msg.setFrom(new InternetAddress(from));
msg.setSubject("Imprest Report");
msg.setContent(messageBody ,"text/html; charset=utf-8");
transport.sendMessage(msg,msg.getAllRecipients());
You would have to add the signature as part of the "content" since I don't think email APIs supports signature as a concept
I have an online form that allows users to email a complaint to the company. To test it I have used gmail smtp as my host. I have no problem receiving the message to the designated email account when the sender is also a gmail but I want the "From" to not be limited to just gmail accounts. It appears that smtp is only good for sending emails from the same server?
Example: My form works great if the from is abc#gmail.com and the company email is company#gmail.com.
However if xyz#yahoo.com is entered for the sender, the receiver company#gmail.com never gets it.
Any help would be greatly appreciated. I can provide my code as well if that is needed.
Your problem is a common security restriction when using SMTP. Outgoing SMTP email can only contain a "mail from" address belonging to the sender. If you break this rule, your email may be considered SPAM.
The following will allow your recipient to reply to an alternate address.
Properties properties = new Properties();
props.put("mail.smtp.from", "abc#gmail.com");
Session session = Session.getDefaultInstance(props, null);
MimeMessage m = new MimeMessage(session);
m.addFrom(InternetAddress.parse("xyz#yahoo.com"));
m.setReplyTo(InternetAddress.parse("xyz#yahoo.com"));
See also
http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/
http://www.openspf.org/Best_Practices/Webgenerated
Well you will have to own the other email as well as set it to work with gmail,
Check here for more details.
It's probably better to send the message to your company's mail server using the identity of the user who owns the application on the server, and include the information that the customer provides in the online form as data in the message you send. The message won't look like it came from the customer, but then it really didn't come from the customer since it wasn't sent using the customer's mail server.